Summary
Hi Guys! I have problem with ansible
Then i execute my playbook. I get error ""VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'stdout'"".
name: show version
hosts: telnet
gather_facts: false
# connection: local
tasks:
- name: CM via telnet
telnet:
login_prompt: "User name: "
prompts:
- '[#]'
command:
- show version
- show lldp info remote
register: telnet_output
- debug: var=telnet_output.stdout.lines
ok: [sw1] => {
"telnet_output.stdout.lines": "VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'stdout'"
}
META: ran handlers
META: ran handlers
PLAY RECAP ************************************************************************************************************************************************************
sw1 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ansible@ansible:~$
I read all documentation about dictionary, but i not understanded. My dictionary is not work.
How is it correct to make dictionary ? And how is it to set up dictionary on Ubuntu 20.04?
I did everythig by documentation ansible.
I maked file stdout_lines
ansible@ansible:~$ ls
1 hosts python stdout_lines telnet_command_sys_info.yml telnetverify.yml.save
ansible.cfg inventory_telnet.yml raw_telnet.yml stdout_lines.yaml telnet_command_sys_info.yml.save Y
dictionary on stdout stdout.yaml telnetverify.yml
ansible@ansible:~$ nano stdout.yaml
GNU nano 4.8 stdout.yaml
---
"stdout": "foo!"
Issue Type
Documentation Report
Component Name
Dictionary
Ansible Version
$ ansible --version ansible 2.10.8 config file = /home/ansible/ansible.cfg configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible executable location = /usr/local/bin/ansible python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0] ansible@ansible:~$
Configuration
$ ansible-config dump --only-changed name: show version hosts: telnet gather_facts: false # connection: local tasks: - name: CM via telnet telnet: login_prompt: "User name: " prompts: - '[#]' command: - show version - show lldp info remote register: telnet_output - debug: var=telnet_output.stdout.lines ok: [sw1] => { "telnet_output.stdout.lines": "VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'stdout'" } META: ran handlers META: ran handlers PLAY RECAP ************************************************************************************************************************************************************ sw1 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ansible@ansible:~$
OS / Environment
ansible@ansible:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
Additional Information
described
Code of Conduct
- I agree to follow the Ansible Code of Conduct
I am trying to get only a portion of the ouput of a command and store the value in a list (for future looping)
tasks: — name: Execute the command win_shell: <command> register: <variable> with_items: — <host1> — <host2>
- name: print the variable
debug: var=<variable>
gives this output:
ok: [immgt4] => { «msg»: { «changed»: true, «msg»: «All items completed», «results»: [ { «_ansible_ignore_errors»: null, «_ansible_item_result»: true, «_ansible_no_log»: false, «_ansible_parsed»: true, «changed»: true, «cmd»: «Install-Module -Name VMware.PowerCLI -scope CurrentUser;Connect-Viserver vcyow -Credential (Import-clixml c:pkgsvm.clixml) -Force > null;(get-vmhost -Name esxfbsmesg1.corp.navcan.ca | get-vm).name», «delta»: «0:00:08.615218», «end»: «2018-04-11 06:06:34.589090», «failed»: false, «item»: «esxfbsmesg1.corp.navcan.ca», «rc»: 0, «start»: «2018-04-11 06:06:25.973871», «stderr»: «», «stderr_lines»: [], «stdout»: «test-host-patching3rntest-host-patching1rntest-host-patchingrn», «stdout_lines»: [ «test-host-patching3», «test-host-patching1», «test-host-patching» ] }, { «_ansible_ignore_errors»: null, «_ansible_item_result»: true, «_ansible_no_log»: false, «_ansible_parsed»: true, «changed»: true, «cmd»: «Install-Module -Name VMware.PowerCLI -scope CurrentUser;Connect-Viserver vcyow -Credential (Import-clixml c:pkgsvm.clixml) -Force > null;(get-vmhost -Name esxfbsmesg2a.corp.navcan.ca | get-vm).name», «delta»: «0:00:09.022712», «end»: «2018-04-11 06:06:44.424300», «failed»: false, «item»: «esxfbsmesg2a.corp.navcan.ca», «rc»: 0, «start»: «2018-04-11 06:06:35.401588», «stderr»: «», «stderr_lines»: [], «stdout»: «test-host-patching5rntest-vm-snapshot4rn», «stdout_lines»: [ «test-host-patching5», «test-vm-snapshot4» ] } ] } }
question: How can i store only the stdout_lines into a new variable it being a list?
when i try anything of the sort of: debug: var=list_vms.stdout
I get this error: The error was: ‘dict object’ has no attribute ‘stdout’
I am very new to ansible and would appreciate your help!
thanks!
The goal for me is to get the result from the first command, put it in a variable and loop trough that list for another command.
Summary
Hi Guys! I have problem with ansible
Then i execute my playbook. I get error ""VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'stdout'"".
name: show version
hosts: telnet
gather_facts: false
# connection: local
tasks:
- name: CM via telnet
telnet:
login_prompt: "User name: "
prompts:
- '[#]'
command:
- show version
- show lldp info remote
register: telnet_output
- debug: var=telnet_output.stdout.lines
ok: [sw1] => {
"telnet_output.stdout.lines": "VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'stdout'"
}
META: ran handlers
META: ran handlers
PLAY RECAP ************************************************************************************************************************************************************
sw1 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
ansible@ansible:~$
I read all documentation about dictionary, but i not understanded. My dictionary is not work.
How is it correct to make dictionary ? And how is it to set up dictionary on Ubuntu 20.04?
I did everythig by documentation ansible.
I maked file stdout_lines
ansible@ansible:~$ ls
1 hosts python stdout_lines telnet_command_sys_info.yml telnetverify.yml.save
ansible.cfg inventory_telnet.yml raw_telnet.yml stdout_lines.yaml telnet_command_sys_info.yml.save Y
dictionary on stdout stdout.yaml telnetverify.yml
ansible@ansible:~$ nano stdout.yaml
GNU nano 4.8 stdout.yaml
---
"stdout": "foo!"
Issue Type
Documentation Report
Component Name
Dictionary
Ansible Version
$ ansible --version ansible 2.10.8 config file = /home/ansible/ansible.cfg configured module search path = ['/home/ansible/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules'] ansible python module location = /usr/local/lib/python3.8/dist-packages/ansible executable location = /usr/local/bin/ansible python version = 3.8.5 (default, Jan 27 2021, 15:41:15) [GCC 9.3.0] ansible@ansible:~$
Configuration
$ ansible-config dump --only-changed name: show version hosts: telnet gather_facts: false # connection: local tasks: - name: CM via telnet telnet: login_prompt: "User name: " prompts: - '[#]' command: - show version - show lldp info remote register: telnet_output - debug: var=telnet_output.stdout.lines ok: [sw1] => { "telnet_output.stdout.lines": "VARIABLE IS NOT DEFINED!: 'dict object' has no attribute 'stdout'" } META: ran handlers META: ran handlers PLAY RECAP ************************************************************************************************************************************************************ sw1 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 ansible@ansible:~$
OS / Environment
ansible@ansible:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
Additional Information
described
Code of Conduct
- I agree to follow the Ansible Code of Conduct
Проблема банальная, смешная, но просто не дает удобно дебажить.
В старой версии ansible 1.6 все отображалось красиво и понятно, сейчас же решив переписать все на версии ansible 2.0.1.0 вывод ошибок например или других операций получается нечитабельным.
Вот так оно отображается сейчас в консоли, при ограниченных размерах окна оно становится в 10 строк монолитного нечитабельного гуано
TASK [proj-test : debug] *************************************************
fatal: [proj-test.loc]: FAILED! => {"failed": true, "msg": "The conditional check 'command_result.stdout.find("is a mountpoint")' failed. The error was: error while evaluating conditional (command_result.stdout.find("is a mountpoint")): 'dict object' has no attribute 'stdout'nnThe error appears to have been in '/***/tasks/test.yml': line 25, column 3, but maynbe elsewhere in the file depending on the exact syntax problem.nnThe offending line appears to be:nn#command_result.stdout.find("is a mountpoint") != -1n- debug: msg={{command_result}}n ^ herenWe could be wrong, but this one looks like it might be an issue withnmissing quotes. Always quote template expression brackets when theynstart a value. For instance:nn with_items:n - {{ foo }}nnShould be written as:nn with_items:n - "{{ foo }}"n"}
to retry, use: --limit @test-playbook.retry
Давновато было, но насколько я помню у меня в старых версиях был такой вывод, и я хотя бы видел на каком этапе произошла ошибка
TASK [proj-test : debug] *************************************************
fatal: [proj-test.loc]: FAILED! => {"failed": true, "msg": "The conditional check 'command_result.stdout.find("is a mountpoint")' failed. The error was: error while evaluating conditional (command_result.stdout.find("is a mountpoint")): 'dict object' has no attribute 'stdout'
The error appears to have been in '/***/tasks/test.yml': line 25, column 3, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
#command_result.stdout.find("is a mountpoint") != -1
- debug: msg={{command_result}}
^ here
We could be wrong, but this one looks like it might be an issue with
missing quotes. Always quote template expression brackets when they
start a value. For instance:
with_items:
- {{ foo }}
Should be written as:
with_items:
- "{{ foo }}" "}
to retry, use: --limit @test-playbook.retry
Устал уже. Гуглил но видимо плохо. Пробовал подключать плагины для изменения вывода callback_plugins, но тоже тщетно. Пробовал: вот из этого блога но оказалось он не совсем хорошо работает со 2 версией, и форк вот этого парня