0

I am running into an issue with Ansible 2.9 where I get the following error after the ec2 instance is created and before it tries to run apt update on that instance the first time around using the playbook I created:

[WARNING]: Could not match supplied host pattern, ignoring: tag_type_master

Yet when I run it the second time, it does find the host matching that tag and continues on with running the apt update and the rest of the playbook tasks.

Here is the command I am running:

ansible-playbook deploy.yaml --private-key ../../../../../Downloads/XXXXXXX.pem --inventory=inventory_aws_ec2.yaml

Here is my deploy.yaml file:

- name: Build out AWS Infrastructure
  hosts: localhost
  connection: local
  gather_facts: False
  roles:
    - role: aws

- name: Setup Master
  hosts: tag_type_master
  remote_user: ubuntu
  become: yes
  roles:
    - role: master

- name: Build Master AMI
  hosts: localhost
  connection: local
  roles:
    - role: master_ami

Here is my inventory_aws_ec2.yaml file:

plugin: aws_ec2
regions:
    - us-east-2
keyed_groups:
  - key: tags.type
    prefix: tag_type_
    separator: ""
hostnames:
    - dns-name
compose:
  ansible_host: dns-name
cache: yes
cache_plugin: memory
cache_timeout: 7200
cache_prefix: aws_ec2

And here is my ansible.cfg file:

[defaults]
host_key_checking = False
fact_caching = memory
cache_timeout = 3600

[inventory_aws_ec2]
enable_plugins = aws_ec2
cache = yes

Is there something that I am missing? Thanks in advance!

UPDATE:

I am also able to run the ansible-inventory command without any issues, and it gives me the expected results:

ansible-inventory -i inventory_aws_ec2.yaml --graph
@all:
  |--@aws_ec2:
  |  |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
  |  |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
  |  |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
  |  |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
  |  |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
  |  |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
  |--@tag_type_master:
  |  |--ec2-XX-XX-XX-XX.us-east-2.compute.amazonaws.com
  |--@ungrouped:
Chris
  • 61
  • 5

3 Answers3

1

I figured it out. I needed to add a refresh_inventory step:

- name: Refresh inventory to ensure new instances exist in inventory
  meta: refresh_inventory
Chris
  • 61
  • 5
0

I don't see any hosts in the inventory file you provided with tag master

should be something like

[master]
127.0.0.1 ansible_connection=local
AWS PS
  • 4,420
  • 1
  • 9
  • 22
  • Thanks for the response, but same result. `[WARNING]: Could not match supplied host pattern, ignoring: tag_type_master` – Chris Jan 06 '20 at 21:23
  • Thanks. I added an update above, but I didn't think that adding the hosts was needed as I I am able to run the `ansible-inventory` command without any issues and I get the expected results. – Chris Jan 07 '20 at 13:13
0

Suspecting a time-sync issue.

  • usually the instance will take some time to spin up and running.
  • you can try adding a sleep/wait_for task and make sure instance is up and running before you do master role.
    - name: Status
      debug:
        msg: "{{ item }} : Waiting for instances online..."
      with_items: "{{ new_ec2_list }}"

Pls share outcome anyway

Thanks

Gineesh
  • 429
  • 1
  • 5
  • 13
  • Thanks. It does wait for the instance to start. I also run the `ansible-inventory` command while the instance is building, and the instance does show up as expected. – Chris Jan 07 '20 at 14:16
  • I meant that the original playbook already waits for the instance to start. This is still not working. When I run `ansible-inventory` during the ec2 creation I get the expected results, so not sure that the wait would do anything, but thanks for following up. – Chris Jan 08 '20 at 14:49