Good Morning
I need to send to a text file a message that appears in debug msg after a check if a directory exists. Follow Playbook below. But it is giving error in the recording of the file.
This is my Playbook
hosts: teste
become: yes
become_user: root
become_method: sudo
gather_facts: yes
tasks:
- name: Verificando Diretórios
stat:
path: /etc/teste_path/
register: path - debug:
msg: “Diretório Ok”
when: path.stat.isdir is defined and path.stat.isdir - debug:
msg: “Diretório Não existe”
when: path.stat.exists == False - debug: var=path.stdout_lines
- name: Gravando Valores
local_action: lineinfile path=/root/find_path.txt line={{path.stdout_lines}}; create=yes
And results with errors:
ASK [Gravando Valores] *************************************************************************************************************************************************************************************
fatal: [10.0.10.117]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘stdout_lines’\n\nThe error appears to have been in ‘/root/Ansible/Playbooks/find_path.yaml’: line 24, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gravando Valores\n ^ here\n\nexception type: <class ‘ansible.errors.AnsibleUndefinedVariable’>\nexception: ‘dict object’ has no attribute ‘stdout_lines’”}
fatal: [10.0.10.122]: FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘dict object’ has no attribute ‘stdout_lines’\n\nThe error appears to have been in ‘/root/Ansible/Playbooks/find_path.yaml’: line 24, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Gravando Valores\n ^ here\n\nexception type: <class ‘ansible.errors.AnsibleUndefinedVariable’>\nexception: ‘dict object’ has no attribute ‘stdout_lines’”}
to retry, use: --limit @/root/Ansible/Playbooks/find_path.retry
Thansk for your attention.