对从此处离开-Ansible的负出口采取行动

问题描述 投票:0回答:1

[我有一本手册,当我的某个地方忽略了一个代理程序时,例如,当我检查是否存在/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/'
python ansible
1个回答
0
投票

您可以只使用“文件”模块来确保目录存在,否则,请创建它。

---
- name: over
  hosts: localhost

  tasks:
   - name: makes sure directory exists or creates it
     file:
       state: directory
       path: /opt/Agent

如果使用此任务,则可以避免所有仅用于“确保”路径存在的验证。

© www.soinside.com 2019 - 2024. All rights reserved.