条件检查项.mount失败

2024-09-30 01:36:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我的剧本不理解我的变量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 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

Tags: namefreethatismainonvaryml

热门问题