I added the following task verifying file exists, and show the results right below it, but I do not know how to reference the results using a "when: " for when the file does not exist. the results shows: " ‘stat’: {‘charset’: ‘binary’, ‘uid’: 0, ‘exists’: True, "
but stat is never found from the error
-
name: check if file exists
local_action: stat path=“/home/pvs/Build/data/{{ item }}.x86_64.rpm”
with_items: “{{ rpms }}”
register: file_stat
-
name: Verifying if file exists
debug: msg=“File {{ item }} exist”
with_items: “{{ file_stat.results }}”
PLAY [Download and install RPMs from a local directory] ***********************************************************************************************************************************************************
TASK [Gathering Facts] ********************************************************************************************************************************************************************************************
ok: [localhost]
TASK [Create directory if it does not exist] **********************************************************************************************************************************************************************
ok: [localhost]
TASK [check if file exists] ***************************************************************************************************************************************************************************************
ok: [localhost → localhost] => (item=Common-1.0.0-37)
ok: [localhost → localhost] => (item=Database-1.0.0-122)
TASK [Verifying if file exists] ***********************************************************************************************************************************************************************************
ok: [localhost] => (item={‘invocation’: {‘module_args’: {‘checksum_algorithm’: ‘sha1’, ‘get_checksum’: True, ‘follow’: False, ‘path’: ‘/home/pvs/Build/data/Common-1.0.0-37.x86_64.rpm’, ‘get_md5’: False, ‘get_mime’: True, ‘get_attributes’: True}}, ‘stat’: {‘charset’: ‘binary’, ‘uid’: 0, ‘exists’: True, ‘attr_flags’: ‘’, ‘woth’: False, ‘isreg’: True, ‘device_type’: 0, ‘mtime’: 1585590258.0, ‘block_size’: 4096, ‘inode’: 5856469, ‘isgid’: False, ‘size’: 205977384, ‘executable’: False, ‘isuid’: False, ‘readable’: True, ‘version’: ‘385713817’, ‘pw_name’: ‘root’, ‘gid’: 0, ‘ischr’: False, ‘wusr’: True, ‘writeable’: True, ‘mimetype’: ‘application/x-rpm’, ‘blocks’: 402312, ‘xoth’: False, ‘islnk’: False, ‘nlink’: 1, ‘issock’: False, ‘rgrp’: True, ‘gr_name’: ‘root’, ‘path’: ‘/home/pvs/Build/data/Common-1.0.0-37.x86_64.rpm’, ‘xusr’: False, ‘atime’: 1673993504.3784745, ‘isdir’: False, ‘ctime’: 1673993447.9204745, ‘isblk’: False, ‘wgrp’: False, ‘checksum’: ‘5738560f3137fb2f62dd9a179ed343daef01c24b’, ‘dev’: 64770, ‘roth’: True, ‘isfifo’: False, ‘mode’: ‘0644’, ‘xgrp’: False, ‘rusr’: True, ‘attributes’: }, ‘changed’: False, ‘failed’: False, ‘item’: ‘Common-1.0.0-37’, ‘ansible_loop_var’: ‘item’}) => {
“msg”: “File {‘invocation’: {‘module_args’: {‘checksum_algorithm’: ‘sha1’, ‘get_checksum’: True, ‘follow’: False, ‘path’: ‘/home/pvs/Build/data/Common-1.0.0-37.x86_64.rpm’, ‘get_md5’: False, ‘get_mime’: True, ‘get_attributes’: True}}, ‘stat’: {‘charset’: ‘binary’, ‘uid’: 0, ‘exists’: True, ‘attr_flags’: ‘’, ‘woth’: False, ‘isreg’: True, ‘device_type’: 0, ‘mtime’: 1585590258.0, ‘block_size’: 4096, ‘inode’: 5856469, ‘isgid’: False, ‘size’: 205977384, ‘executable’: False, ‘isuid’: False, ‘readable’: True, ‘version’: ‘385713817’, ‘pw_name’: ‘root’, ‘gid’: 0, ‘ischr’: False, ‘wusr’: True, ‘writeable’: True, ‘mimetype’: ‘application/x-rpm’, ‘blocks’: 402312, ‘xoth’: False, ‘islnk’: False, ‘nlink’: 1, ‘issock’: False, ‘rgrp’: True, ‘gr_name’: ‘root’, ‘path’: ‘/home/pvs/Build/data/Common-1.0.0-37.x86_64.rpm’, ‘xusr’: False, ‘atime’: 1673993504.3784745, ‘isdir’: False, ‘ctime’: 1673993447.9204745, ‘isblk’: False, ‘wgrp’: False, ‘checksum’: ‘5738560f3137fb2f62dd9a179ed343daef01c24b’, ‘dev’: 64770, ‘roth’: True, ‘isfifo’: False, ‘mode’: ‘0644’, ‘xgrp’: False, ‘rusr’: True, ‘attributes’: }, ‘changed’: False, ‘failed’: False, ‘item’: ‘Common-1.0.0-37’, ‘ansible_loop_var’: ‘item’} exist”
}
ok: [localhost] => (item={‘invocation’: {‘module_args’: {‘checksum_algorithm’: ‘sha1’, ‘get_checksum’: True, ‘follow’: False, ‘path’: ‘/home/pvs/Build/data/Database-1.0.0-122.x86_64.rpm’, ‘get_md5’: False, ‘get_mime’: True, ‘get_attributes’: True}}, ‘stat’: {‘charset’: ‘binary’, ‘uid’: 0, ‘exists’: True, ‘attr_flags’: ‘’, ‘woth’: False, ‘isreg’: True, ‘device_type’: 0, ‘mtime’: 1612995841.0, ‘block_size’: 4096, ‘inode’: 1629, ‘isgid’: False, ‘size’: 12408, ‘executable’: False, ‘isuid’: False, ‘readable’: True, ‘version’: ‘235891764’, ‘pw_name’: ‘root’, ‘gid’: 0, ‘ischr’: False, ‘wusr’: True, ‘writeable’: True, ‘mimetype’: ‘application/x-rpm’, ‘blocks’: 40, ‘xoth’: False, ‘islnk’: False, ‘nlink’: 1, ‘issock’: False, ‘rgrp’: True, ‘gr_name’: ‘root’, ‘path’: ‘/home/pvs/Build/data/Database-1.0.0-122.x86_64.rpm’, ‘xusr’: False, ‘atime’: 1674050294.847356, ‘isdir’: False, ‘ctime’: 1673994773.5614717, ‘isblk’: False, ‘wgrp’: False, ‘checksum’: ‘56730380852174a19f81253383a540689399ea9b’, ‘dev’: 64770, ‘roth’: True, ‘isfifo’: False, ‘mode’: ‘0644’, ‘xgrp’: False, ‘rusr’: True, ‘attributes’: }, ‘changed’: False, ‘failed’: False, ‘item’: ‘Database-1.0.0-122’, ‘ansible_loop_var’: ‘item’}) => {
“msg”: “File {‘invocation’: {‘module_args’: {‘checksum_algorithm’: ‘sha1’, ‘get_checksum’: True, ‘follow’: False, ‘path’: ‘/home/pvs/Build/data/Database-1.0.0-122.x86_64.rpm’, ‘get_md5’: False, ‘get_mime’: True, ‘get_attributes’: True}}, ‘stat’: {‘charset’: ‘binary’, ‘uid’: 0, ‘exists’: True, ‘attr_flags’: ‘’, ‘woth’: False, ‘isreg’: True, ‘device_type’: 0, ‘mtime’: 1612995841.0, ‘block_size’: 4096, ‘inode’: 1629, ‘isgid’: False, ‘size’: 12408, ‘executable’: False, ‘isuid’: False, ‘readable’: True, ‘version’: ‘235891764’, ‘pw_name’: ‘root’, ‘gid’: 0, ‘ischr’: False, ‘wusr’: True, ‘writeable’: True, ‘mimetype’: ‘application/x-rpm’, ‘blocks’: 40, ‘xoth’: False, ‘islnk’: False, ‘nlink’: 1, ‘issock’: False, ‘rgrp’: True, ‘gr_name’: ‘root’, ‘path’: ‘/home/pvs/Build/data/Database-1.0.0-122.x86_64.rpm’, ‘xusr’: False, ‘atime’: 1674050294.847356, ‘isdir’: False, ‘ctime’: 1673994773.5614717, ‘isblk’: False, ‘wgrp’: False, ‘checksum’: ‘56730380852174a19f81253383a540689399ea9b’, ‘dev’: 64770, ‘roth’: True, ‘isfifo’: False, ‘mode’: ‘0644’, ‘xgrp’: False, ‘rusr’: True, ‘attributes’: }, ‘changed’: False, ‘failed’: False, ‘item’: ‘Database-1.0.0-122’, ‘ansible_loop_var’: ‘item’} exist”
}
TASK [Download RPMs] **********************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {“msg”: “The conditional check ‘item.stat.exists == True’ failed. The error was: error while evaluating conditional (item.stat.exists == True): ‘ansible.utils.unsafe_proxy.AnsibleUnsafeText object’ has no attribute ‘stat’\n\nThe error appears to be in ‘/home/pvs/Build/playbooks/DownloadRPM.yml’: line 31, 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: Download RPMs\n ^ here\n”}
PLAY RECAP ********************************************************************************************************************************************************************************************************
localhost : ok=4 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0