Re: [ansible-project] How do i loop over include_vars objects under a dictionary ?

2020-03-01 Thread Vladimir Botka
> > On Sun, 1 Mar 2020 21:37:42 -0800 (PST) 
> > Shifa Shaikh > wrote: 
> >  
> > > listings.yml 
> > > 
> > > --- 
> > > 10.9.9.42: 
> > >   - name: myapp 
> > > path: /app/myapp_war.ear/myapp.war 
> > >   - name: myapp JS 
> > > path: /app/myapp_war.ear/myapp.war/javascripts 
> > > 10.9.9.43: 
> > >   - name: CVS 
> > > path: /app/CVS.ear/CVS.war/ui/js 
> > >   - name: CHK 
> > > path: /app/logs/tmp 
> > >   - name: SSO 
> > > path: /app/CVS.ear/CVS.war/WEB-INF 
> > > 
> > > [...] 
> > > 
> > >   tasks: 
> > >- name: Load entire repository inventory 
> > >  include_vars: 
> > >file="{{ playbook_dir }}/vars/listing.yml" 
> > > name: user1 
> > > 
> > >- debug: 
> > >msg: "Name {{ item.0.name }} on path{{ item.0.path }}" 
> > >  loop: 
> > >- "{{ inventory_hostname }}"   
> >
> > The variables from the file are assigned into the dictionary "user1". Fix 
> > the 
> > variables' references 
> >
> > - debug: 
> > msg: "Name {{ user1[item].0.name }} on path {{ user1[item].0.path 
> > }}" 
> >   loop: 
> > - "{{ inventory_hostname }}" 
> >
> > With single item the loop is not necessary 
> >
> > - debug: 
> > msg: "Name {{ user1[inventory_hostname].0.name }} on 
> >   path {{ user1[inventory_hostname].0.path }}" 


> I wish to loop all name and path under the given host. 

Try this

- debug:
msg: "Name {{ item.name }} on path {{ item.path }}"
  loop: "{{ user1[inventory_hostname] }}"

HTH,

-vlado

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200302072347.203ee28b%40gmail.com.


pgpNEIZHq88Xx.pgp
Description: OpenPGP digital signature


Re: [ansible-project] How do i loop over include_vars objects under a dictionary ?

2020-03-01 Thread Shifa Shaikh
@Vladimir this prints only the first name and path under the hostname. 

I wish to loop all name and path under the given host. 

On Monday, March 2, 2020 at 11:40:36 AM UTC+5:30, Vladimir Botka wrote:
>
> On Sun, 1 Mar 2020 21:37:42 -0800 (PST) 
> Shifa Shaikh > wrote: 
>
> > listings.yml 
> > 
> > --- 
> > 10.9.9.42: 
> >   - name: myapp 
> > path: /app/myapp_war.ear/myapp.war 
> >   - name: myapp JS 
> > path: /app/myapp_war.ear/myapp.war/javascripts 
> > 10.9.9.43: 
> >   - name: CVS 
> > path: /app/CVS.ear/CVS.war/ui/js 
> >   - name: CHK 
> > path: /app/logs/tmp 
> >   - name: SSO 
> > path: /app/CVS.ear/CVS.war/WEB-INF 
> > 
> > [...] 
> > 
> >   tasks: 
> >- name: Load entire repository inventory 
> >  include_vars: 
> >file="{{ playbook_dir }}/vars/listing.yml" 
> > name: user1 
> > 
> >- debug: 
> >msg: "Name {{ item.0.name }} on path{{ item.0.path }}" 
> >  loop: 
> >- "{{ inventory_hostname }}" 
>
> The variables from the file are assigned into the dictionary "user1". Fix 
> the 
> variables' references 
>
> - debug: 
> msg: "Name {{ user1[item].0.name }} on path {{ user1[item].0.path 
> }}" 
>   loop: 
> - "{{ inventory_hostname }}" 
>
> With single item the loop is not necessary 
>
> - debug: 
> msg: "Name {{ user1[inventory_hostname].0.name }} on 
>   path {{ user1[inventory_hostname].0.path }}" 
>
> HTH, 
> -vlado 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2a93b4ce-6d1a-428f-8853-12555789dbfe%40googlegroups.com.


Re: [ansible-project] How do i loop over include_vars objects under a dictionary ?

2020-03-01 Thread Vladimir Botka
On Sun, 1 Mar 2020 21:37:42 -0800 (PST)
Shifa Shaikh  wrote:

> listings.yml
> 
> ---
> 10.9.9.42:
>   - name: myapp
> path: /app/myapp_war.ear/myapp.war
>   - name: myapp JS
> path: /app/myapp_war.ear/myapp.war/javascripts
> 10.9.9.43:
>   - name: CVS
> path: /app/CVS.ear/CVS.war/ui/js
>   - name: CHK
> path: /app/logs/tmp
>   - name: SSO
> path: /app/CVS.ear/CVS.war/WEB-INF
>
> [...]
>
>   tasks:
>- name: Load entire repository inventory
>  include_vars:
>file="{{ playbook_dir }}/vars/listing.yml"
> name: user1
> 
>- debug:
>msg: "Name {{ item.0.name }} on path{{ item.0.path }}"
>  loop:
>- "{{ inventory_hostname }}"

The variables from the file are assigned into the dictionary "user1". Fix the
variables' references

- debug:
msg: "Name {{ user1[item].0.name }} on path {{ user1[item].0.path }}"
  loop:
- "{{ inventory_hostname }}"

With single item the loop is not necessary

- debug:
msg: "Name {{ user1[inventory_hostname].0.name }} on
  path {{ user1[inventory_hostname].0.path }}"

HTH,
-vlado

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/20200302071017.4a7fae12%40gmail.com.


pgpD2GstzGpBR.pgp
Description: OpenPGP digital signature


[ansible-project] How do i loop over include_vars objects under a dictionary ?

2020-03-01 Thread Shifa Shaikh
I have a include_vars file with the below entries in listings.yml

---
10.9.9.42:
  - name: myapp
path: /app/myapp_war.ear/myapp.war
  - name: myapp JS
path: /app/myapp_war.ear/myapp.war/javascripts
10.9.9.43:
  - name: CVS
path: /app/CVS.ear/CVS.war/ui/js
  - name: CHK
path: /app/logs/tmp
  - name: SSO
path: /app/CVS.ear/CVS.war/WEB-INF


Output:

TASK [Load entire repository inventory] 
*
task path: /app/test.yml:57
ok: [10.9.9.42] => {
"ansible_facts": {
"10.9.9.42": [
{
"name": "myapp",
"path": "/app/myapp_war.ear/myapp.war"
},
{
"name": "myapp JS",
"path": "/app/myapp_war.ear/myapp.war/javascripts"
}
],
"10.9.9.43": [
{
"name": "CVS",
"path": "/app/CVS.ear/CVS.war/ui/js"
},
 {
"name": "CHK",
"path": "/app/logs/tmp"
},
{
"name": "SSO",
"path": "/app/CVS.ear/CVS.war/WEB-INF"
}
]
},
"ansible_included_var_files": [
"/app/vars/listing.yml"
],
"changed": false
}


TASK [debug] 

task path: /app/test.yml:62
fatal: [10.9.9.42]: FAILED! => {
"msg": "The task includes an option with an undefined variable. The 
error was: 'unicode object' has no attribute 'name'\n\nThe error appears to 
be in '/app/test.yml': line 62, column 6, but may\nbe elsewhere in the file 
depending on the exact syntax problem.\n\nThe offending line appears to 
be:\n\n\n   - debug:\n ^ here\n"
}




Below is my playbook where i wish to read all the name and path under the 
inventory_hostname so if the inventory_hostname remote host is "10.9.9.42" 
all the names and path under it should be displayed.

  tasks:


   - name: Load entire repository inventory
 include_vars:
   file="{{ playbook_dir }}/vars/listing.yml"
name: user1


   - debug:
   msg: "Name {{ item.0.name }} on path{{ item.0.path }}"
 loop:
   - "{{ inventory_hostname }}"

   
Can you please suggest whats wrong with my playbook ?

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/3d0e239c-c74a-4753-a81b-df2601b82731%40googlegroups.com.