0

I created a playbook with 6 different tasks and want to run tasks 1,2,3 only when host is a child of was855node group (e.g. b, c) and tasks 4,5 to run only when hosts is child of was855dmgr group (e.g. a)

My inventory file:

[local-linux:children]
was855

[was855:children]
was855dmgr
was855node

[was855dmgr:children]
hppidc-pps-dmgr
hppndc-pps-dmgr
hppb-pps-dmgr

**hreg1-mnp-dmgr**

[was855node:children]
wppdev3-pps-node
hint1-pps-node

**hreg1-mnp-node**

[hreg1-mnp-dmgr]
a 

[hreg1-mnp-node]
b 
c 

is this the correct way to do it?

- name: Run create-app-logs.py on the Nodes ***(i want to run it on a ONLY)***
  shell: "{{ was_profile_path }}/bin/wsadmin.sh -lang jython -f {{ build_scripts_dir }}/create-app-logs.py"
  register: r
  when: "'was855dmgr' in group_names"
  tags: create_app_logs

- name: Create shared libraries directory ***(i want to run it on b and c ONLY)***
  file: path={{ was_shared_lib_location }} state=directory owner=wasadm group=apps mode=0755
  when: "'was855node' in group_names"
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Daniyal
  • 11
  • 2

1 Answers1

0

You would typically split this out into separate plays within the same playbook, and use the hosts directive to control where each play is executed.

For example:

- name: Play 1
  hosts: was855dmgr
  tasks:
    - task1
    - task2
    - task3

- name: Play 2
  hosts: was855node
  tasks:
    - task4
    - task5

- name: Play 2
  hosts: all
  tasks:
    - task6
Matt P
  • 2,452
  • 1
  • 12
  • 15