Score:0

How to make Ansible run batch of tasks on few nodes but one by one (nodes running in cluster)

ธง cn

I have an ansible playbook which looks roughly like this:

- hosts: node1
      tasks:
      - name: get cluster state 
        shell: "RESTAPI 1 command"
      - name: put cluster in upgrade mode
        shell: "RESTAPI 2 command"
- hosts: node 1
      tasks:
      - name: upgrade Apache
        shell: "upgrade Apache command"
      - name: start Apache
        shell: "start Apache command"
- hosts: node 1
      tasks:
      - name: healthy check for Apache is running
        shell: "RESTAPI command"
- hosts: node 2
      tasks:
      - name: upgrade Apache
        shell: "upgrade Apache command"
      - name: start Apache
        shell: "start Apache command"
- hosts: node 2
      tasks:
      - name: healthy check for Apache is running
        shell: "RESTAPI command"
- hosts: node 3
      tasks:
      - name: upgrade Apache
        shell: "upgrade Apache command"
      - name: start Apache
        shell: "start Apache command"
- hosts: node 3
      tasks:
      - name: healthy check for Apache is running
        shell: "RESTAPI command"

I want to improve the playbook that will run as a loop because for each node I have same commands that should be exec on each node one by one because all nodes running in cluster and I need only one node will be in upgrade process at the same time. also I have few environment (Test/Dev) that I want to use this playbook but I have different nodes number in cluster how can I make run the playbook no matter how many nodes I have into the cluster?

Score:1
ธง in

คุณสามารถวางงานที่เกิดซ้ำทั้งหมดลงในบล็อกได้ ผสมผสานกับ อนุกรม: 1 คุณต้องแน่ใจว่าดำเนินการเพียงบล็อกเดียวในแต่ละครั้ง

- โฮสต์: โหนด
  อนุกรม: 1
  งาน:
    - ชื่อ: รับสถานะคลัสเตอร์ 
      เชลล์: "คำสั่ง RESTAPI 1"
      run_once: ใช่
    - ชื่อ: ทำให้คลัสเตอร์อยู่ในโหมดอัปเกรด
      เชลล์: "คำสั่ง RESTAPI 2"
      run_once: ใช่
    - บล็อก:
      - ชื่อ: อัปเกรด Apache
        เปลือก: "อัพเกรดคำสั่ง Apache"
      - ชื่อ: เริ่ม Apache
        เชลล์: "เริ่มคำสั่ง Apache"
      - ชื่อ: การตรวจสอบความสมบูรณ์สำหรับ Apache กำลังทำงานอยู่
        เชลล์: "คำสั่ง RESTAPI"
# ลองใหม่: 20
# ล่าช้า: 15

ฉันสันนิษฐานว่าคำสั่งให้คลัสเตอร์อยู่ในโหมดอัปเกรดสามารถรันบนโหนดใดก็ได้ ดังนั้นคุณสามารถใช้ run_once. หากไม่ใช่กรณีนี้และต้องรันบนโหนดเฉพาะ คุณสามารถใช้ a เมื่อไร ข้อจำกัดสำหรับโฮสต์เฉพาะ

สำหรับสุขภาพ ตรวจสอบพารามิเตอร์ ล่าช้า และ ลองใหม่ อาจเป็นที่สนใจ หากมีความเป็นไปได้ที่การตรวจสอบจะล้มเหลวในตอนแรกและสำเร็จเมื่อ apache ทำงานเต็มที่

หากต้องการใช้ playbook กับกลุ่มโฮสต์ต่างๆ ที่คุณสามารถใช้ได้ โฮสต์: ทั้งหมด จากนั้น จำกัด โฮสต์ให้อยู่ในกลุ่มระหว่างการดำเนินการ

ansible-playbook upgrade.yml --limit dev_nodes
cn flag
สวัสดี @GeraldSchneider ขอบคุณสำหรับการตอบกลับ ฉันพยายามแก้ไขไฟล์ yml ตามคำแนะนำของคุณ แต่ฉันได้รับข้อผิดพลาดทางไวยากรณ์ ข้อผิดพลาด! 'uri' ไม่ใช่แอตทริบิวต์ที่ถูกต้องสำหรับบล็อก `- โฮสต์: โหนด อนุกรม: 1 งาน: - ชื่อ: รับสถานะคลัสเตอร์ ยูริ: run_once: ใช่ บล็อก: - ชื่อ: คัดลอก สำเนา: - ชื่อ: ไฟล์ ไฟล์ - ชื่อ: การตรวจสอบ systemd ระบบ: - ชื่อ: blockinfile บล็อคอินไฟล์ # ลองใหม่: 20 # ล่าช้า: 15 `
in flag
อ่านยากในความคิดเห็น แต่ดูเหมือนว่าคุณใช้โคลอนในชื่องาน คุณต้องอ้างอิงเมื่อคุณทำเช่นนั้น

โพสต์คำตอบ

คนส่วนใหญ่ไม่เข้าใจว่าการถามคำถามมากมายจะปลดล็อกการเรียนรู้และปรับปรุงความสัมพันธ์ระหว่างบุคคล ตัวอย่างเช่น ในการศึกษาของ Alison แม้ว่าผู้คนจะจำได้อย่างแม่นยำว่ามีคำถามกี่ข้อที่ถูกถามในการสนทนา แต่พวกเขาไม่เข้าใจความเชื่อมโยงระหว่างคำถามและความชอบ จากการศึกษาทั้ง 4 เรื่องที่ผู้เข้าร่วมมีส่วนร่วมในการสนทนาด้วยตนเองหรืออ่านบันทึกการสนทนาของผู้อื่น ผู้คนมักไม่ตระหนักว่าการถามคำถามจะมีอิทธิพลหรือมีอิทธิพลต่อระดับมิตรภาพระหว่างผู้สนทนา