我有一本手册,其中检查了我是否可以安装该代理,我想做什么以及以下情况:当我的某个地方存在被忽略的代理时,例如,我在其中检查是否存在/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
如果使用此任务,则可以避免所有仅用于“确保”路径存在的验证。
知道了,谢谢您的回答,如果您想在未满足条件的情况下关闭剧本,该怎么办?
您可以将任务与“ meta”模块一起使用,并将“ end_play”与“ when”语句结合使用。
好的,非常感谢 !