I'm using the AWS dynamic inventory script for ansible as described here to pull a subset of my EC2 instances based on their tags. I would like to set up a multistage environment where I can run my playbooks on DEV or PRD using this dynamic inventory script.
I have my project directory set up as:
ansible.cfg
inventories/
-- dev/
-- ec2.ini
-- group_vars/
-- host_vars
-- inventory
-- prd/
-- ec2.ini
-- group_vars/
-- host_vars
-- inventory
playbooks/
-- playbook1.yml
-- playbook2.yml
-- playbook3.yml
roles/
site.yml
The inventory
file in the dev
and prd
directories is dynamic inventory script.
I have each ec2.ini file set up to create a dynamic inventory based on AWS tags for dev or prd environments.
If I attempt to run ansible-playbook -i dev site.yml
I get an error: [WARNING]: Unable to parse /home/ansibleadmin/dev_playbook/dev as an inventory source
This method is supposed to work for static inventories--does it not work with dynamic inventories for some reason? What would be the proper way to achieve this?
You get a warning:
[WARNING]: Unable to parse /home/ansibleadmin/dev_playbook/dev as an inventory source
The directory in the warning message /home/ansibleadmin/dev_playbook/dev
does not exist on your machine, according to the "project directory" tree which you posted above.
The correct command using a relative path (while in the playbook directory) is:
ansible-playbook -i inventories/dev site.yml
The correct command using an absolute path is:
ansible-playbook -i /home/ansibleadmin/dev_playbook/inventories/dev site.yml