windowws
windowws

Reputation: 377

Single role multiple hosts different tasks

I have a playbook with multiple tasks for a single role, i want to divide the tasks say 80% to first host and remaining 20% to second host , the first and second host will be picked from

ansible-playbook -i 1.2.3.4, 2.3.4.5, update.yml 

where 1.2.3.4 is first server ip and 2.3.4.5 is second server ip. How can i achieve this.

Upvotes: 0

Views: 3128

Answers (2)

sklemmer
sklemmer

Reputation: 71

To recap: You have one role with 10 tasks. 6 of which you want to execute on server 1 and the rest on server 2

A way would be to write 2 different playbooks which will include the tasks you want to execute on the specified hosts. Another might be to use tags on each task and execute ansible with --tags and specify them on playbook level

- hosts: all
  tags:
    - foo
  role:
    ...

- hosts: all
  tags: 
    - bar
  role:
    ...

ref https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html

Upvotes: 1

error404
error404

Reputation: 2823

Playbook tasks execution can be controlled by tags or blocks. My previous answer was related to the task execution on few of the hosts(I miss understood)

For eg. serial: "80%"

would mean that all the tasks will be performed on 80% of the hosts first then will be performed on the remaining hosts.

For playbook to execute some tasks on few hosts and some on few hosts you can may be use when with ansible_hostname set to some hosts

Upvotes: 0

Related Questions