What I am trying to accomplish:
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
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?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.