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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/5f4a4ebb-0b39-4faf-bb2d-b9e99b0a13cdn%40googlegroups.com.