Using ansible-playbook --tags=xxx with dynamic inventory

180 views
Skip to first unread message

Alex D.

unread,
Jan 12, 2022, 4:21:53 PM1/12/22
to Ansible Project
Hi,

I tried to run a playbook with a dynamic inventory (see my playbook below) using e.g. ansible-playbook -i nms-vms init-vrf-nms.yml --extra-vars "nms=nms-sz" --tags=basic

Unfortunately, i got the following error:
~
[WARNING]: Could not match supplied host pattern, ignoring: dynamically_created_hosts

PLAY [Initialize selected VRF NMS] ***********************************************************************************************************************************************************************************************************
skipping: no hosts matched


When i use --skip-tags, it works as expected. I wonder if running ansible-playbooks with tags included is even supported ?

init-vrf-nms.yml
---
- hosts: localhost
  gather_facts: no

  vars_prompt:
    - name: nms
      prompt: Which VRF NMS should be initialized
      private: no

  tasks:
    - name: "Add host to dynamic inventory"
      add_host:
        name: "{{ nms }}"
        groups: dynamically_created_hosts

# ---------------------------------------------------------

- name: "Initialize selected VRF NMS"
  hosts: dynamically_created_hosts
  become: yes

  tasks:

  - name: "Apply role 'nms-basic'"
    include_role:
      name: nms-basics
    tags:
      - basics

  - name: "Apply role 'vrf-vm'"
    include_role:
      name: vrf-vm
    tags:
      - vrf-vm

Regards,
Alex

Brian Coca

unread,
Jan 12, 2022, 4:23:48 PM1/12/22
to Ansible Project
show output of `ansible-inventory -i nms-vms --list`

--
----------
Brian Coca

Alex D.

unread,
Jan 12, 2022, 5:14:19 PM1/12/22
to Ansible Project
Here's the output. Some vars are obfuscated

$ ansible-inventory -i nms-vms --list
{
    "_meta": {
        "hostvars": {
            "nms-sz": {
                "Files": [],
                "ansible_become_method": "sudo",
                "ansible_common_remote_group": "sysadmins",
                "ansible_host": "172.28.x.x",
                "ansible_password": "xxx",
                "ansible_ssh_common_args": "-o StrictHostKeyChecking=no",
                "ansible_sudo_pass": "xxx",
                "ansible_user": "xxx",
                "mrtg": {
                    "sample_dir": "sz",
                    "sample_router": "sz-r1.4711"
                },
                "netplan": {
                    "ens160": {
                        "ipv4": {
                            "address": "172.28.x.x",
                            "gateway": "172.28.x.x",
                            "netmask": "255.255.255.128",
                            "prefix_length": 25
                        }
                    },
                    "ens192": {
                        "ipv4": {
                            "address": "192.168.x.x",
                            "netmask": "255.255.x.x",
                            "prefix_length": 30,
                            "routes": [
                                {
                                    "to": "192.168.250.0/24",
                                    "via": "192.168.x.x"
                                },
                                {
                                    "to": "172.30.95.22/32",
                                    "via": "192.168.x.x"
                                }
                            ]
                        }
                    }
                },
                "network_gear": {
                    "access": [
                        "ssh",
                        "telnet"
                    ],
                    "snmp_community": "xxx"
                },
                "nginx": {
                    "enabled": false,
                    "state": "stopped"
                },
                "rancid_groups": [
                    "sz"
                ],
                "rancid_user": "xxx",
                "rancid_user_pass": "xxx",
                "syslog_facilities": [
                    "local7"
                ]
            }
        }
    },
    "all": {
        "children": [
            "ungrouped",
            "vrf_nms"
        ]
    },
    "vrf_nms": {
        "hosts": [
            "nms-sz"
        ]
    }
}

Clint Denham

unread,
Jan 12, 2022, 5:30:09 PM1/12/22
to ansible...@googlegroups.com
In your ansible-playbook command it references the tag "basic" but the playbook itself references "basics". Could you update and try again?

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/47b900b9-df78-4ecd-8168-eb1d49b11da6n%40googlegroups.com.

Alex D.

unread,
Jan 13, 2022, 9:42:18 AM1/13/22
to Ansible Project
Sorry, that was just an error while cut&paste in my first post.

$ ansible-playbook -i nms-vms init-vrf-nms.yml --check --diff --extra-vars "nms=nms-sz" --tags=basics

PLAY [localhost] *****************************************************************************************************************************************************************************************************************************

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

PLAY [Initialize selected VRF NMS] ***********************************************************************************************************************************************************************************************************
skipping: no hosts matched

PLAY RECAP ***********************************************************************************************************************************************************************************************************************************

What makes me suspicious is the message "Could not match supplied host pattern, ignoring: dynamically_created_hosts"

$ ansible-playbook -i nms-vms init-vrf-nms.yml --extra-vars "nms=nms-sz" --list-tags
[WARNING]: Could not match supplied host pattern, ignoring: dynamically_created_hosts

playbook: init-vrf-nms.yml

  play #1 (localhost): localhost        TAGS: []
      TASK TAGS: []

  play #2 (dynamically_created_hosts): Initialize selected VRF NMS      TAGS: []
      TASK TAGS: [basics, vrf-vm]

Regards,
Alex
Reply all
Reply to author
Forward
0 new messages