H
H
HighMan2021-07-26 18:51:34
Ansible
HighMan, 2021-07-26 18:51:34

How to perform an action for a single host in ansible-playbook?

Hello colleagues!
And ansible, I'm not a great specialist, so I ask you not to kick hard with your feet.

#cat hosts
[master]
master
[mirror]
mirror
[slaves]
s1
s2
s3
s4
s5
s6

Most of the actions I need to perform for all hosts. But there are separate operations that need to be performed only on the master or mirror further so that some of the operations are performed on the slaves. Is it possible to somehow implement these actions in the form of one playbook?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxKozlov, 2021-07-26
@MaxKozlov

So, actually write a playbook

- hosts: master
  pre_tasks:
    - name: task will run before roles
      copy: ...
  roles:
    - role: master_role
  tasks:
    - name: task will run after roles
      copy: ...

- hosts: mirror
  vars:
     var_for_mirror_group: 42
  roles:
    - role: mirror_role
  tasks:
    - name: task 1
      template: ...
    - name: task 2
      copy: ...

- hosts: slaves
  roles:
    - role: slaves_role

- hosts: all
  roles:
    - role: all_together_role

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question