我创建了一个包含6个不同任务的剧本,并且只想在主机是was855node
组(例如b
、c
(的子级时运行任务1、2、3,而任务4、5只想在宿主是was855dmgr
组(如a
(的子代时运行
我的库存文件:
[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
这是正确的方法吗?
- 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"
您通常会在同一剧本中将其拆分为不同的剧本,并使用hosts
指令来控制每个剧本的执行位置。
例如:
- name: Play 1
hosts: was855dmgr
tasks:
- task1
- task2
- task3
- name: Play 2
hosts: was855node
tasks:
- task4
- task5
- name: Play 2
hosts: all
tasks:
- task6