1
votes

I am new to Ansible, so I assume I am making a silly mistake, however when I try to run a playbook with roles for a group of hosts, Ansible doesn't see any hosts in some groups. In particular

Inventory has among others the following group:

[master]
clm01

It seems to be working OK with Ad-hoc commands:

:~/ansible/splunk# ansible master -i hosts -m ping -u USERNAME
clm01 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

However, when I try to run the following, Ansible can't see any hosts:

- name: initialize master
  hosts: master
  remote_user: USERNAME
  become: yes
  roles:
    - cluster_master
[...]

ansible-playbook site.yml --ask-sudo-pass --list-hosts
[...]
  play #2 (master): initialize master   TAGS: []
    pattern: [u'master']
    hosts (0):
[...]

Some of the groups in the inventory are working with other plays defined in the same file, so I would assume there is a syntax error on my side. I have also tried changing group name, hoping I am using a reserved name etc.

2

2 Answers

0
votes

It doesn't see any hosts, because you omitted -i hosts parameter in the second command.

Run the following:

ansible-playbook site.yml -i hosts --ask-sudo-pass --list-hosts
-1
votes

I think it needs to look like this:

- hosts: master
  remote_user: USERNAME
  become: yes
  become_user: root

  roles:
    - cluster_master

That name tag is for plays.