I'm receiving the below error when trying to deploy the below Ansible script. It is related to the copying of the yum output to a .txt file and does seem to be something trivial with the syntax. Any help decoding the error would be much appreciated.
TASK [copy the output to a local file]*****************************************
fatal: [Dev-01]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout'\n\nThe error appears to be in '/tmp/awx_728_j8h4pd86/project/linux-patch-script-1.yml': line 26, 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: copy the output to a local file\n ^ here\n"}**
fatal: [Prod-01]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stdout'\n\nThe error appears to be in '/tmp/awx_728_j8h4pd86/project/linux-patch-script-1.yml': line 26, 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: copy the output to a local file\n ^ here\n"}****
---
- hosts: all
become: yes
tasks:
- name: yum-clean-metadata
command: yum clean metadata
args:
warn: no
- name: Old CF output file for same of handover
shell: rpm -qa --queryformat "%{NAME};%{VERSION}-%{RELEASE}\n" | sort -t\; -k 1 > /tmp/yum-Installed-pre.txt
- name: Set variable to number of installed packages and available updates
shell: "{{ item }}"
with_items:
- export pre_pkg_inst=$(yum list installed | grep '^[a-Z0-9]' | wc -l)
- export pre_pkg_avail=$(yum check-update --quiet | grep '^[a-Z0-9]' | wc -l)
- echo -n "${HOSTNAME};${pre_pkg_inst};${pre_pkg_avail};" > /tmp/$HOSTNAME-yum-install.txt
- name: Run yum update and output details
yum:
name: '*'
state: latest
register: yumoutput
- name: copy the output to a local file
copy:
content: "{{ yumoutput.stdout }}"
dest: "/tmp/yum-update.txt"
- name: Reboot machine after update
reboot:
msg: Reboot initiated by Ansible after patching
post_reboot_delay: 30
reboot_timeout: 600
'dict object' has no attribute 'stdout'
=> debug the content ofyumoutput
and you will see it does not contain anystdout
key. Choose the correct key you want to display in your file, or the entire varialb all together, in yaml format for convenience =>content: "{{ yumoutput | to_nice_yaml(indent=2) }}"
– Zeitounator