เมื่อเหตุผลของพฤติกรรมเป็นดีงั้นพูดโดย @flowerysong เป็นคำตอบนั่นคือ workaround คุณสามารถใช้เพื่อประสบความสำเร็จของคุณสำคัญที่สุ.
เคล็ดลับคือการใช้ความจริงที่ว่าคุณสามารถกำหนดสองคนเล่นในสมุดขอและก็ใช้ตัวแปรตั้งค่าบนเครื่อง(s)ของเล่นครั้งแรก.
ดังนั้นสิ่งที่เราจะต้องทำคือ:
- ไปเล่นบน
localhost
และตั้งเป็นข้อเท็จจริงมาจากเครื่องกลุ่มที่เราต้องเล็งเป้าหมายอยู่ในที่สองเล่น
- Optionally:ฉันยังกำหนดไว้เป็น
target_hosts
ตัวแปรที่เล่นครั้งแรกเพื่อที่จะแน่ใจว่าถ้าคนสองเล่นเป็นเป้าหมายคือการแก้ไขที่เครื่องกลุ่มตัวแปรก็คือต้องกลายเป็นคนที่สองเล่นจะต้องเป้าหมาย
- ใช้ตัวแปรในครั้งที่สอเล่นจากกอง
localhost
's hostvars
เพิ่มข้อควรจำ:ไม่มีบัญชีสำหรับรสนิยมนะแต่ฉันชอบที่ แสดงในตัวจดหมาย message status ถ้า ไป ternary
ตัวกรองยัง,พวกเขาเข้มงวดมพล่ามคำเชยๆออกมาไม่หยุด.
ดังนั้น,ดูจากสมุดของ:
- hosts: localhost
gather_facts: no
tasks:
- set_fact:
target_hosts: nodes
- set_fact:
host_set: "{{ hostvars[groups[target_hosts].0].host_set }}"
- hosts: "{{ hostvars.localhost.target_hosts }}"
gather_facts: no
serial: "{{ '100%' if hostvars.localhost.host_set else '1' }}"
tasks:
- debug:
- เมื่อประมวลผลด้วย
host_set: true
ใน nodes
กลุ่ม:
PLAY [localhost] *******************************************************************************************************************
TASK [set_fact] ********************************************************************************************************************
ok: [localhost]
TASK [set_fact] ********************************************************************************************************************
ok: [localhost]
PLAY [nodes] ***********************************************************************************************************************
TASK [debug] ***********************************************************************************************************************
ok: [node1] =>
msg: Hello world!
ok: [node2] =>
msg: Hello world!
ok: [node3] =>
msg: Hello world!
PLAY RECAP *************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
node1 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
node2 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
node3 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- เมื่อประมวลผลด้วย
host_set: false
ใน nodes
กลุ่ม:
PLAY [localhost] *******************************************************************************************************************
TASK [set_fact] ********************************************************************************************************************
ok: [localhost]
TASK [set_fact] ********************************************************************************************************************
ok: [localhost]
PLAY [nodes] ***********************************************************************************************************************
TASK [debug] ***********************************************************************************************************************
ok: [node1] =>
msg: Hello world!
PLAY [nodes] ***********************************************************************************************************************
TASK [debug] ***********************************************************************************************************************
ok: [node2] =>
msg: Hello world!
PLAY [nodes] ***********************************************************************************************************************
TASK [debug] ***********************************************************************************************************************
ok: [node3] =>
msg: Hello world!
PLAY RECAP *************************************************************************************************************************
localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
node1 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
node2 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
node3 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0