当断言模块跳过主机的条件时 Ansible

问题描述

我正在编写一个剧本,它首先会检查 /tmp 是否有专用分区,然后它将状态重定向到 CSV 文件(成功和失败),然后成功的主机将测试 /var 1G 的文件系统空闲空间,如果成功,它将状态写入 CSV,失败也会写入 CSV,但如果使用以下剧本跳过任务,我将无法写入 CSV,请对此提供帮助:

- name: Check if /tmp is separate mountpoint
  command: mountpoint /tmp
  register: mount
  ignore_errors: yes

- name: Reporting Success nodes to patching_report.csv
  shell: "sed -i '/^{{ inventory_hostname }}/ s/$/,tmp_AVAILABLE/g' /tmp/patching_report.csv"
  delegate_to: localhost
  when: mount.rc == 0

- name: Reporting Failed nodes to patching_report.csv
  shell: "sed -i '/^{{ inventory_hostname }}/ s/$/,tmp_NOT_AVAILABLE/g' /tmp/patching_report.csv"
  delegate_to: localhost
  when: mount.rc == 1

- name: Reporting Skipped nodes to patching_report.csv
  shell: "sed -i '/^{{ inventory_hostname }}/ s/$/,SKIPPED/g' /tmp/patching_report.csv"
  delegate_to: localhost
  when: mount is skipped

- debug:
    msg: "{{ inventory_hostname}} proceed further"
  when: mount.rc == 0

- name: Check if /var filesystem has 1G freespace
  assert:
    that:
      - item.size_available > 1024000000
    fail_msg: '/var space is less than 1G'
    success_msg: '/var space is sufficient'
    quiet: true
  when: item.mount == "/var"
  with_items: "{{ ansible_mounts }}"
  register: result
  ignore_errors: yes
  when: mount.rc == 0

- name: Reporting Success nodes to patching_report.csv
  shell: "sed -i '/^{{ inventory_hostname }}/ s/$/,VAR_FREE/g' /tmp/patching_report.csv"
  delegate_to: localhost
  when: mount.rc == 0 and result is succeeded

- name: Reporting Failed nodes to patching_report.csv
  shell: "sed -i '/^{{ inventory_hostname }}/ s/$/,VAR_FREE/g' /tmp/patching_report.csv"
  delegate_to: localhost
  when: mount.rc == 0 and result is Failed

- name: Reporting Skipped nodes to patching_report.csv
  shell: "sed -i '/^{{ inventory_hostname }}/ s/$/,SKIPPED/g' /tmp/patching_report.csv"
  delegate_to: localhost
  when: result is skipped

- debug:
    msg: "{{ inventory_hostname}} proceed further"
  when: mount.rc == 0 and result is succeeded

================================================ ======== cat /tmp/patching_report.csv 本地主机,tmp_AVAILABLE,VAR_FREE 172.17.254.201,tmp_NOT_AVAILABLE

在上面的 csv 文件中,第二个主机在断言条件中被跳过,但同样没有反映在跳过的主机条件中。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)