I have my inventory separated into environment-specific directories, with an ec2 dynamic inventory script in each inventory dir. Each ec2 inventory script filters out instances by their “Environment” tag. I run my playbooks by using the ‘-i’ command-line parameter and pointing to the specific environment inventory I want to run, which normally works.
However, I ran into an issue this morning where I was trying to run a playbook against my staging servers but ansible-playbook was instead running it over my prod servers. I re-ran it a few times, including --list-hosts to confirm the instances it was trying to apply the playbook to, but it was still using my prod inventory. I also confirmed that I was using ‘-i inventory/stage/’ in the command, which I was.
I had a thought, and removed both /tmp/ansible_fact_cache and ~/.ansible/tmp/* and re-ran the exact same command, and this time my staging inventory was used correctly.
Is this a known issue? Have I configured something wrong here? I’m very confused by this behaviour.
Thanks,
Guy