Giter Club home page Giter Club logo

ansible-role-aws_account_match's Introduction

Ansible AWS account match

The aws_account_match role let's you define one or more AWS accounts and ensures your playbook is only provisioned against those accounts.

Include this role at the very top of any AWS relatated playbooks and it will act as a safeguard by immediately aborting the whole play in case you are logged in with the wrong AWS account.

Boto profiles and environment variables are both supported.

Build Status Ansible Galaxy Release


Installation

Ensure aws-cli is installed locally:

$ pip install awscli

Either use Ansible Galaxy to install the role:

$ ansible-galaxy install cytopia.aws_account_match

Or git clone it into your roles directory

$ git clone https://github.com/cytopia/ansible-role-aws_account_match /path/to/ansible/roles

Variables

Note: (XOR)

  • Either aws_account_match_allowed_account or aws_account_match_allowed_accounts must be specified.
  • Only one of aws_account_match_allowed_account or aws_account_match_allowed_accounts can be specified.
Name Type Description
aws_account_match_allowed_account int or string Single allowed account
aws_account_match_allowed_accounts list Multiple allowed accounts
aws_account_match_profile string Optional boto profile of current login

Requirements

Usage

playbook.yml
---
- hosts: all
  roles:
    - aws_account_match  # <- make sure it is the first
    - aws-do-this
    - aws-do-that
    - aws-more-work
  tags:
    - aws
group_vars/all.yml
---
# Allow two AWS accounts
aws_account_match_allowed_accounts:
  - 123456789
  - 987654321

# Ensure to have boto profile optionally parsed via cmd args
aws_account_match_profile: "{{ profile | default('') }}"
Run

The testing boto profile has a login for account 555444333222, which is not part of the allowed accounts. In case this is run, it will immediately abort the whole play:

$ ansible-playbook playbook.yml -e profile=testing
TASK [aws_account_match : ensure current account matched any of all allowed accounts] **************************
fatal: [infrastructure]: FAILED! => {
    "assertion": "_aws_account_match_number.stdout | string in aws_account_match_allowed_accounts | map('string') | list",
    "changed": false,
    "evaluated_to": false,
    "msg": "Currently logged in account (555444333222) not in allowed accounts (123456789, 987654321)."
}
Run without aws_account_match

You can also skip the whole role in case you need to test without account validation via its pre-defined tags:

$ ansible-playbook playbook.yml -e profile=testing --skip-tags=aws_account_match

ansible-role-aws_account_match's People

Contributors

cytopia avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.