[我有一本手册,当我的某个地方忽略了一个代理程序时,例如,当我检查是否存在/opt/Agent/
时,我将检查是否可以安装该代理程序,以及我想做什么。目录,否则我想创建此目录,该怎么做?
---
- hosts: all
tasks:
- name: 'Ensure that free space on /opt/Agent/ is grater than 1.5GB'
assert:
that: item.size_available >= 1500000000
msg: 'disk space has reached 1.5GB threshold'
when: item.mount == mountname
with_items: '{{ ansible_mounts }}'
- name: Ansible check agent is present.
stat:
path: /etc/init.d/agent
register: file_details
- debug:
msg: "Agent is present"
when: file_details.stat.exists
- name: Ansible check directory Agent exists.
stat:
path: /opt/Agent/
register: files_to_delete
- debug:
msg: "Directory Agent exists"
when: files_to_delete.stat.exists and files_to_delete.stat.isdir
vars:
mountname: '/opt/Agent/'
您可以只使用“文件”模块来确保目录存在,否则,请创建它。
---
- name: over
hosts: localhost
tasks:
- name: makes sure directory exists or creates it
file:
state: directory
path: /opt/Agent
如果使用此任务,则可以避免所有仅用于“确保”路径存在的验证。