Ansible 创建文件,然后说它不存在

时间:2021-04-02 13:51:02

标签: linux ansible

我有一个运行许多任务的剧本,但其中一个任务是创建一个文件,然后几个任务是将该文件用于输出以进行验证,但它失败了。如果 Ansible 在它之前创建了 20 个任务,我不明白这个任务是如何失败的。

剧本任务:

- name: Validate Local directory exists
  become: yes
  ansible.builtin.file:
    path: /opt/file
    state: directory

- name: Set new sslPassword for server.pem
  become: yes
  ini_file:
    path: /opt/file/file1.conf
    section: Config
    option: Password
    value: "{{ key_password }}"
    mode: 0755

- name: Grab value from /opt/file/file1.conf 
  slurp:
    src: '{{ local_path.server }}'
  register: slurp_cert_local_config

结果:

TASK [create_file : Set new password for item.pem] *****************
task path: /opt/ansible/roles/create_file/tasks/set_new_pass.yml:20
changed: [server1] => {"changed": true, "gid": 1018, "group": "ansible", "mode": "0755", "msg": "section and option added", "owner": "ansible", "path": "/opt/file/file1.conf", "size": 60, "state": "file", "uid": 1018}

....a bunch of stuff.....

TASK [create_file : Grab value from dw-certs_ansible/local/item.conf] ***
task path: /opt/ansible/roles/create_file/tasks/main.yml:51
fatal: [server1]: FAILED! => {"changed": false, "msg": "file not found: /opt/file/file1.conf"}

0 个答案:

没有答案