1
votes

The goal is to run this play against all hosts but each role should only run as follows:

  • lab01-4 for webservers
  • lab01-5 for databases
  • lab01-6 for others

We have several hosts in different groups:

[webservers]
rhel-01
[databases]
rhel-02
[others]
rhel-03

We have several roles in one play with tags:

- hosts: all
  become: yes
  roles:
    - { role: 'lab01-4', tags: 'webservers', hosts: 'webservers' }
    - { role: 'lab01-5', tags: 'databases', hosts: 'databases' }
    - { role: 'lab01-6', tags: 'others', hosts: 'others' }

I see that there is no keyword hosts in role (https://docs.ansible.com/ansible/latest/reference_appendices/playbooks_keywords.html#role). Ansible ignores keyword hosts and starts play without errors for all hosts.

Any suggestions?

1

1 Answers

0
votes

Q: "Each role should only run as follows"

lab01-4 for webservers
lab01-5 for databases
lab01-6 for others

A: For example run each play as follows

- hosts: webservers
  become: yes
  roles:
    - lab01-4
- hosts: databases
  become: yes
  roles:
    - lab01-5
- hosts: others
  become: yes
  roles:
    - lab01-6