Using Ansible ansible 2.4.2.0
I'm trying to run only a certain play from the main playbook (main.yml
)
---
# main playbook for cluster deployment
# initial configuration of OS same for all hosts
- name: Cluster Deployer playbook
hosts: all
roles:
- { role: common, tags: ['initial_config'] }
# configuration specific for loadbalancers hosts group
- name: Cluster Deployer playbook - Load Balancer setup
hosts: loadbalancers
roles:
- { role: loadbalancers_setup, tags: ['setup_loadbalancer'] }
# configuration specific for db-servers hosts group
- name: Cluster Deployer playbook - Database servers setup
hosts: db-servers
roles:
- { role: db_servers_setup, tags: ['setup_db_server'] }
# configuration specific for web-servers hosts group
- name: Cluster Deployer playbook - Web Servers setup
hosts: web-servers
roles:
- { role: web_servers_setup, tags: ['setup_web_server'] }
Here's my hosts
file
[loadbalancers]
192.168.99.10
[db-servers]
192.168.99.2
[web-servers]
192.168.99.3
192.168.99.4
I'm calling the playbook with the command
ansible-playbook main.yml --inventory hosts --tags initial_config
The problem is that Ansible runs all plays from that playbook even though I've requested only those with tag initial_config
in the roles
section. I've tried with setting the tags
section under hosts
but with no luck.
Is it possible to define tags on this level without the need for tagging individual tasks in roles? I'm new to Ansible so if there is a better way of writing playbooks, I'm all ears.