I am having around 250 Debian files in a directory /home/emgda/del/ which periodically changes and must be installed by everyday end.
So I am trying to write an Ansible script to loop this directory, hold file names in an array then install all Debian sequentially using command sudo dpkg -i file_name
So far below is the code I have listed out the files in the directory, just need to add command:
somehow to execute above command,
---
- hosts: local
gather_facts: false
tasks:
- command: "ls /home/emgda/del/"
register: dir_out
- debug: var={{item}}
with_items: dir_out.stdout_lines
OUTPUT is
PLAY [local] ***********************************************************************************************************
TASK [command] ************************************************************************************************************************
changed: [localhost]
TASK [debug] ************************************************************************************************************************
ok: [localhost] => (item=dir_out.stdout_lines) => {
"dir_out.stdout_lines": [
"a.deb"
],
"item": "dir_out.stdout_lines"
}
PLAY RECAP ************************************************************************************************************************
localhost : ok=2 changed=1 unreachable=0 failed=0
Any help will be deeply appreciated.
2
Answers
Well I solved it using below technique.
A: find the packages and install them in the loop with apt
It’s possible to query plugin fileglob and install the packages in one task