条件检查item.mount失败

时间:2020-02-14 13:14:03

标签: python ansible

我的剧本无法理解变量DIRLOGMOUNTS,我是否缺少层次结构?

结构

playbooks
|   └── start_linux.yml
|  
|   
roles
|  └── preRequirements
|      └── tasks
|          └── main.yml                         
group_vars
  └── main.yml

任务

    # Check space directory /var/logs/
      - name: 'Ensure that free space on /var/logs/ is grater than 1.5Gb'
        assert:
          that: item.size_available >= 1500000000
        when: item.mount == DIRLOG
        with_items: MOUNTS
        ignore_errors: yes
        register: disk_free

      - block:
          - debug:
              msg: "Disk (/var/logs/) space has reached 1.5Gb threshold"
          - meta: end_play
        when: disk_free is failed

  - debug:
      msg: "Sufficient disk space (/var/logs/), continue play"

VARS

#################################################################################
# Variables global
#################################################################################

DIRLOG        : '/var/logs/'
MOUNTS        : "{{ ansible_mounts }}"

PLAYBOOK

# playbook for linux
---
- hosts: all
  vars_files:
    - ../group_vars/all.yml
  gather_facts: false
  tasks:
    - name: Check Pre Requirements for install agent
      import_role:
        name: preRequirements
        tasks_from: main

错误

TASK [preRequirements : Ensure that free space on /var/logs/ is grater than 1.5Gb] ************************************************************************
fatal: [client_test]: FAILED! => {"msg": "The conditional check 'item.mount == DIRLOG' failed. The error was: error while evaluating conditional (item.mount == DIRLOG): 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'mount'\n\nThe error appears to be in '/etc/ansible/roles/preRequirements/tasks/main.yml': line 17, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n# Check space directory /var/logs/\n  - name: 'Ensure that free space on /var/logs/ is grater than 1.5Gb'\n    ^ here\n"}
...ignoring

1 个答案:

答案 0 :(得分:0)

错误很简单,经过几个小时的研究,找到了解决方案:

gather_facts: yes

我将离开POST,以帮助以后遇到相同问题的人

https://docs.ansible.com/ansible/latest/modules/gather_facts_module.html