0
votes

I'm using ansible to configure and deploy several servers in ec2. Since these servers are frequently changing I'd like to use dynamic inventory. I have set up ec2.py and ec2.ini in my jenkins server (this is where the ansible scripts are run) but am running into an issue when I run the playbook:

ERROR! Specified --limit does not match any hosts

Which clearly means that my hosts are not being selected correctly. When I run:

./ec2.py --list >> aws_example.json

everything looks good in aws_example.json.

I'm trying to select servers based on two tags, Name and environment. For example, I have a server with a 'Name' tag of 'api' and an 'environment' tag of 'production'.


I've set up the destination_format_tags like so:

destination_format_tags = Name,environment

and run ansible as follows:

ansible-playbook site.yml -i ec2.py -l api

I've also tried changing the hostname_variable:

hostname_variable = tag_Name.tag_environment

and running the command like so:

ansible-playbook site.yml -i ec2.py -l api.production

Additionally, I've also tried using only one tag with the hostname_variable:

hostname_variable = tag_Name

and running the command like so:

ansible-playbook site.yml -i ec2.py -l api

None of these configurations work. I'm also unable to find much documentation about these setting so I'm not sure how to correctly configure it. Can anyone point me in the right direction?

1
How are you executing the playbook? Post the command line including arguments.helloV
@helloV I've updated the question to include the command.cscan

1 Answers

2
votes

So the problem was how I was representing my host names in my playbook. Setting the hostname variable was the right thing to do:

hostname_variable = tag_Name

And here's how to represent it in the playbook:

- name: configure and deploy api servers
  hosts: tag_Name_api
  remote_user: ec2-user
  sudo: true

  roles:
  - java
  - nginx
  - api

Additionally, it'll need to be called like so:

ansible-playbook site.yml -i ec2.py -l tag_Name_api

Make sure to change special characters such as . or - to _.