首页 > 解决方案 > 如何获取包含任务 --playbook 中每个任务的状态?

问题描述

我在 with_together 循环中作为 ansible playbook 在下面执行,但需要知道定义为 switch-host-config.yaml 的每个任务的状态,但是当我打印寄存器变量“sw_output”时,它没有显示任务结果,它显示了 with_together定义列表...是否有任何方法或方式来识别定义的 switch-host-config.yaml 剧本中的任务状态。

- hosts: "{{ data_sw_ip1 }}"
  connection: local
  gather_facts: False
  tasks:
    - name: sw-host task
      include_tasks: switch-host-config.yaml
      vars:
        - nic1_swport: "{{ item.0 }}"
        - nic2_swport: "{{ item.1 }}"
        - id_host: "{{ item.2}}"
      register: sw_output
      with_together:
        - "{{ nic1_swport1 }}"
        - "{{ nic2_swport }}"
        - "{{ id_host }}"
      ignore_errors: yes

    - debug:
        msg: "{{ sw_output }}"

标签: ansible

解决方案


推荐阅读