ali haider
ali haider

Reputation: 20202

accessing file name with find module of ansible

I am using the find module in ansible to get the first file (on a remote server) that matches the pattern I have mentioned in the find module. I am getting an exception in the debug message - should I be using another mechanism to achieve this?

  find: paths="/home/ubuntu/" patterns="*.deb"
  register: test_build

- debug: msg={{ test_build.files.0.path }}
  shell: dpkg -i {{ test_build.files.0.path }}
  become: True
  become_user: root 
  become_method: sudo

Upvotes: 0

Views: 3616

Answers (1)

techraf
techraf

Reputation: 68519

I'm not sure what this question is about (you did not show the error message), but the playbook excerpt you included contains simple syntax errors (two tasks are squeezed into one). Fixing them makes the tasks work:

- find: paths="/home/ubuntu/" patterns="*.deb"
  register: test_build

- debug: msg={{ test_build.files.0.path }}

- shell: dpkg -i {{ test_build.files.0.path }}
  become: True
  become_user: root 
  become_method: sudo

Upvotes: 1

Related Questions