I am new to Ansible, and I am writing a script to install a package when disk space is more then a limit. I am getting error like this >> error while evaluating conditional
---
- hosts: dev
become: true
become_user: root
tasks:
- name: Install zsh if enough space
yum:
name: zsh
state: latest
with_items: "{{ ansible_mounts}}"
when: item.mount == "/" and item.size_available > 10737400
I am giving the size in bytes. ( Is there a way to give the size in MB ? )
Thanks.
Ansible uses the YAML format, you need to use the right indent. In YAML, the indent is important as closing brackets or semicolons in most programming languages.
with_items
is not a definition for the yum
module, it is a directive for Ansible, so it should be at the same level as when
and the module call (eg yum
). Both examples below should work:
---
- hosts: dev
become: true
become_user: root
tasks:
- name: Install zsh if enough space
yum:
name: zsh
state: latest
with_items: "{{ ansible_mounts }}"
when: item.mount == "/" and item.size_available > 10737400
or
---
- hosts: dev
become: true
become_user: root
tasks:
- name: Install zsh if enough space
with_items: "{{ ansible_mounts }}"
when: item.mount == "/" and item.size_available > 10737400
yum:
name: zsh
state: latest
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.