Question

Ansible issues with locate command

Posted August 5, 2019 541 views
Ansible

What I am trying to accomplish:

  1. Get list of commands that I want to run:
    [db2inst1@db2server1 ~]$ locate db2ilist | grep instance
    /opt/ibm/db2/V10.5/instance/db2ilist
    /opt/ibm/db2/V11.1/instance/db2ilist

  2. Execute both of the commands above

First issue is that Ansible does not seem to be playing well with the locate command:

- name: Update locate database
  command: /bin/updatedb

- name: Gather DB2 DB2 instances
  command: /bin/locate 'db2ilist' | /bin/grep 'instance'
  register: db2ilist_output

I get a rather large list of all files that have ‘instance’ in the name somewhere. I expected to only get the 2 files listed above.

Second issue is… once I have both executables inside the db2ilist_output register, how do I loop through them to execute them?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Was able to resolve the questions with:

- name: Update locate database
  command: /bin/updatedb

- name: Gather DB2 DB2 instances
  shell: /bin/locate 'db2ilist' | /bin/grep 'instance'
  register: db2ilist_cmd

- debug: msg="{{ db2ilist_cmd.stdout_lines }}"

- name: List each DB2 instance
  command: "{{ item }}"
  with_items: "{{ db2ilist_cmd.stdout_lines}}"
  register: db2ilist_output
Submit an Answer