Does your "register: file_stat" needs to be moved up to the file task?
Walter -- Walter Rowe, Division Chief Infrastructure Services, OISM Mobile: 202.355.4123 On Jan 17, 2023, at 1:13 PM, Matthew Franco <francom...@gmail.com> wrote: with what I am doing shouldn't file_stat get registered as part of the loop? What am I doing wrong? I get the following error when trying to run my script below: 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 [Download RPMs] *********************************************************** fatal: [localhost]: FAILED! => {"msg": "The conditional check 'file_stat.stat.exists == False' failed. The error was: error while evaluating conditional (file_stat.stat.exists == False): 'file_stat' is undefined\n\nThe error appears to be in '/home/pvs/Build/playbooks/DownloadRPM.yml': line 17, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n mode: 0755\n - name: Download RPMs\n ^ here\n"} My script: --- - name: Download and install RPMs from a local directory hosts: all vars_files: - rpms.yml tasks: - name: Create directory if it does not exist file: path: /home/pvs/Build/data state: directory mode: 0755 - name: Download RPMs yum: name: "{{ item }}" state: present enablerepo: "*" dest: /home/pvs/Build/data/ with_items: "{{ rpms }}" when: file_stat.stat.exists == False register: file_stat - name: Install RPMs from local directory yum: name: /home/pvs/Build/data/{{ item }} .x86_64.rpm state: present installroot: /home/pvs/Build/data enablerepo: "*" allowdowngrade: yes with_items: "{{ rpms }}" register: yum_result - name: check if package installation failed debug: msg: "RPM {{ item.name }} failed with error {{ item.rc }}" with_items: "{{ yum_result.results }}" when: item.rc != 0 This Ansible script loads the list of RPMs to download from a separate file called "rpms.yml" using the vars_files directive. This file should be in the same directory as the playbook and should be in YAML format. The file should contain a list of RPMs names like this: rpms: - file1 - file2 - file3 Background on my script: This Ansible script first uses the yum command to download the RPMs to a local directory, it will also check if the file already exists in the directory before downloading it, if it already exists it will skip the downloading task. Once all the files are downloaded, it will use the yum command again to install the RPMs from the local directory. Please make sure to provide the correct path to the directory where you want to store the RPMs, and the correct file names in the rpms.yml file. any help would be appreciated. Thank you -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com<mailto:ansible-project+unsubscr...@googlegroups.com>. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/5f4a4ebb-0b39-4faf-bb2d-b9e99b0a13cdn%40googlegroups.com<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F5f4a4ebb-0b39-4faf-bb2d-b9e99b0a13cdn%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7C08e179f9dd494bace8f808daf8b6d736%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638095761438814493%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Rq%2B4owRVfaszrNHevaEBYtzXJnVFZ9nn2oj6dBVuJUU%3D&reserved=0>. -- You received this message because you are subscribed to the Google Groups "Ansible Project" group. To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/998E6BDC-3DCA-4490-ACFB-BA57DD096341%40nist.gov.