I have to read every line from a text file and add that in yaml. Here is my play book
- hosts: localhost
tasks:
- name: Register a file content as a variable
ansible.builtin.shell: cat /home/packages.txt
register: result
- name: Print the transformed variable
ansible.builtin.debug:
msg: '{{ item }}'
loop: '{{ result.stdout | list }}'
- name: install
shell: yum install '{{ item }}'
loop: '{{ result.stdout | list }}'
packages.txt contains
nginx
vim
grafana
When I run this, the packages are not getting installed. This is the console output,
TASK [Register a file content as a variable] **********************************************************************************
changed: [localhost]
TASK [Print the transformed variable] *****************************************************************************************
TASK [install] ****************************************************************************************************************
PLAY RECAP ********************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=2 rescued=0 ignored=0
Requirement is to install those packages from the text file through this ansible playbook