K2 Cloud Ansible Dynamic Inventory is a scripts for managing your cloud infrastructure dynamically.
git clone ${THIS_REPO_URL}
cd ${THIS_REPO_NAME}
python3.6 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
To use this inventory script please set up your credentials using ~/.aws/credentials
file.
Add the following to your config:
[k2]
aws_access_key_id = <YOUR_ACCESS_KEY>
aws_secret_access_key = <YOUR_SECRET_KEY>
Now specify your aws profile using environment variables export AWS_PROFILE=k2
.
Or you can pass this variable before every command AWS_PROFILE=k2 ansbile-playbook ...
You can also specify your credentials locally.
For this modify contrib/inventory/ec2.ini
file with:
aws_access_key_id = <YOUR_ACCESS_KEY>
aws_secret_access_key = <YOUR_SECRET_KEY>
All examples located in examples
folder.
To execute playbook on instances marked with Tag web_server
playbook.yaml:
- hosts: tag_Name_web_server
connection: local
gather_facts: false
tasks:
- name: Example
command: time
Use command: ansible-playbook -i contrib/inventory/ec2.py playbook.yaml
To list all your hosts use
ansible-inventory --list -i contrib/inventory/ec2.py