I'm not able to figure out how I can pass a nested variable as parameter to Ansible's shell module & invoke the script "check.sh" however, below is what I tried.
---
- name: "Find the details here "
hosts: localhost
tasks:
- name: set_fact
set_fact:
fpath_APP: "{{ fpath_APP + [ item.split('.')[0] ~ '/' ~ item | basename ] }}"
with_items:
- "{{ Source_Files.split(',') }}"
vars:
fpath_APP: []
- name: Invoke shell script
- shell: "./check.sh {{ Number }} '{{ vars['fpath_' + Layer] }}' > hello.txt"
tasks:
- name: Ansible find files multiple patterns examples
find:
paths: /home/examples
patterns: "*.db"
recurse: yes
register: files_matched
- name: Search for Number in the matched files
command: grep -i {{ Number }} {{ item.path }}
with_items:
- "{{ files_matched.files }}"
The above playbook runs but does not invoke the shell module and completes without doing anything. See Output below:
$ ansible-playbook fpath.yml -e " Source_Filenames=/tmp/logs/filename1.src,/tmp/logs/33211.sql,/app/axmw/Jenkins/file1.mrt
Layer=APP Number=57550" [WARNING]: provided hosts list is empty, only
localhost is available. Note that the implicit localhost does not
match 'all'
[WARNING]: While constructing a mapping from fpath.yml, line 2,
column 3, found a duplicate dict key (tasks). Using last defined value
only.
PLAY [Find the details here]
**************************************************************************************************************************************************
TASK [Gathering Facts]
******************************************************************************************************************************************************** ok: [localhost]
PLAY RECAP
******************************************************************************************************************************************************************** localhost : ok=1 changed=0 unreachable=0
failed=0 skipped=0 rescued=0 ignored=0
Below are my failed attempts at changing the shell module syntax:
- shell: "./check.sh {{ Number }} '{{ 'fpath_' + vars[Layer] }}' > hello.txt"
Does not invoke Shell module
- shell: "./check.sh {{ Number }} '/"{{ vars['fpath_' + Layer] }}/"' > hello.txt"
Gives Syntax Error.
- shell: "./check.sh {{ Number }} /"'{{ vars['fpath_' + Layer] }}'/" > hello.txt"
Gives Syntax Error.
I'm on the latest version of ansible and python version is 2.7.5.
[WARNING]: While constructing a mapping from fpath.yml, line 2, column 3, found a **duplicate dict key (tasks)**. Using last defined value only.This clearly indicates that the playbook you pasted is not the one you are running. Yours contains a duplicatetasksentry which is empty and this is why no tasks are played (or you are including the posted playbook in an other one withinclude_tasksrather thaninclude_playbook). There are other potential problems in your tasks but fix that first and try to go further.