Re: [ansible-project] Adding a Fact to a dict for Cisco Interf.

2019-08-27 Thread Vladimir Botka
> - set_fact:
> cisco_ios: "{{ cisco_ios.interfaces|combine(interfaces) }}"

Errata:

 - set_fact:
 cisco_ios: "{{ cisco_ios|combine({'interfaces': interfaces}) }}"

-- 
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/20190827173855.1c2d1563%40gmail.com.


pgpm5issBoP3s.pgp
Description: OpenPGP digital signature


Re: [ansible-project] Adding a Fact to a dict for Cisco Interf.

2019-08-27 Thread Vladimir Botka
On Tue, 27 Aug 2019 07:44:24 -0700 (PDT)
Spiro Mitsialis  wrote:

> I have the following that is not working.  
> 
>   vars:
> cmdb: xkjsdflkjsjdl4d
> cisco_ios:
>interfaces:
>  gigabit1/0/1:
> name: Gigabit1/0/1
> status: up
>  gigabit1/0/2:
> name: Gigabit1/0/2
> status: down
> [...]
> I want to end up with
> 
> cisco_ios:
> interfaces:
>gigabit1/0/1:
>   name: Gigabit1/0/1
>   status: up
>   cmdbId: xx
>gigabit1/0/2:
>name: Gigabit1/0/2
>status: down
>cmdbId: xx

Is this probably what are you looking for?

- set_fact:
interfaces: "{{ interfaces|default({})|
combine({item.key: item.value|
combine({'cmdbId': cmdb})}) }}"
  loop: "{{ cisco_ios.interfaces|dict2items }}"
- set_fact:
cisco_ios: "{{ cisco_ios.interfaces|combine(interfaces) }}"

Cheers,

-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/20190827172342.22b64016%40gmail.com.


pgpYDDl1OhuYV.pgp
Description: OpenPGP digital signature


[ansible-project] Adding a Fact to a dict for Cisco Interf.

2019-08-27 Thread Spiro Mitsialis
I have the following that is not working.  

  vars:
cmdb: xkjsdflkjsjdl4d
cisco_ios:
   interfaces:
 gigabit1/0/1:
name: Gigabit1/0/1
status: up
 gigabit1/0/2:
name: Gigabit1/0/2
status: down
  tasks:
  - name: Test in loop
include: test_loop_fact2.yml
loop: "{{ cisco_ios.interfaces | dict2items }}"
  - debug:
 var: cisco_ios

*test_loop_fact2**.yml:*

- name: set fact
  set_fact:
 new_fact:
   interfaces:
   "{{ item.key }}":
  cmdbId: "{{ cmdb }}"

- name: merge
  set_fact:
 cisco_ios: "{{ cisco_ios|combine(new_fact,recursive=True) }}"
 cacheable: true


I want to be able to insert cmdbId under cisco_ios.interfaces.gigabit1/0/1 
and cisco_ios.interfaces.gigabit1/0/2 but I cannot figure out how to do 
this.  With the above I get:

TASK [debug] 

ok: [127.0.0.1] => {
"cisco_ios": {
"interfaces": {
"gigabit1/0/1": {
"name": "Gigabit1/0/1",
"status": "up"
},
"gigabit1/0/2": {
"name": "Gigabit1/0/2",
"status": "down"
},
"{{ item.key }}": {
"cmdbId": "xkjsdflkjsjdl4d"
}
}
}
}


I've tried removing the "{{ }}" and tried [ ] but get errors.  How do I 
reference it.
I want to end up with

cisco_ios:
interfaces:
   gigabit1/0/1:
  name: Gigabit1/0/1
  status: up
  cmdbId: xx
   gigabit1/0/2:
   name: Gigabit1/0/2
   status: down
   cmdbId: xx

-- 
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/c49e522a-f81b-4b36-ac65-4dbb01f35a5e%40googlegroups.com.