[ansible-project] How create vlans if he don't exist in the file gathred by ios_facts

2020-01-16 Thread Kaouane Alaaeddine
Hello,

I want to create (configurate) "vlan" in my device (switch) when it is not 
available on my equipment 
  

for configurate or ( add) vlan in the switch I use the module  "ios_vlans"

for gather facts of my device I use "ios_facts"

you will find below how are stored all the vlans currently available on my 
equipment 

"ansible_network_resources": {
"vlans": [
{
"mtu": 1500,
"name": "default",
"shutdown": "disabled",
"state": "active",
"vlan_id": 1
},
{
"mtu": 1500,
"name": "V2-SPA-LAN-A-Admin",
"shutdown": "disabled",
"state": "active",
"vlan_id": 2
},
{
"mtu": 1500,
"name": "VLAN0010",
"shutdown": "disabled",
"state": "active",
"vlan_id": 10
},
{
"mtu": 1500,
"name": "Total",
"shutdown": "disabled",
"state": "active",
"vlan_id": 20
},
{
"mtu": 1500,
"name": "youpi",
"shutdown": "disabled",
"state": "active",
"vlan_id": 222
}

I'm trying to find of way of how doing it thanks to when conditionnal in 
ansible but can't find it.
Thanks for you help 

-- 
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/1956c19d-eef2-4274-b696-1c4d246590cd%40googlegroups.com.


Re: [ansible-project] register results in a text file after retrieving it on a device with (gather_facts)

2020-01-16 Thread Kaouane Alaaeddine
Hello Brian,
thanks you for your answer,
I've already tried to used the template fonction but i can solves this
issus " i don't know exactly what i must to do
I am a very beginner in this field, i don't understand all of ansible,
i want some help can, and orient me or help to bluid this script

regards


Le mer. 15 janv. 2020 à 18:48, Brian Coca  a écrit :

> instead of the 2 debug statements use a `template` action
> https://docs.ansible.com/ansible/latest/modules/template_module.html if
> you delegate_to: localhost it will write the file on the controller.
>
> --
> --
> Brian Coca
>
> --
> 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/CACVha7dzV9ZWkCXtFUpki8v-WnS2y%3D-YdnQO68QOyiTvp%2BfatA%40mail.gmail.com
> 
> .
>

-- 
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/CALterY2V37D5GudXb8uYzgi6BmEnt8GLbFs%2BOEdZtfM0exXu4w%40mail.gmail.com.


[ansible-project] register results in a text file after retrieving it on a device with (gather_facts)

2020-01-15 Thread Kaouane Alaaeddine
Hello all 

my tesk consist to register the number of vlan available in the device ( 
cisco switch) in a texte file 

1) I want to get just the value of vlan sotred in the item"vlan_id" 

I hope someone can help me :)


This my script 



---
- hosts:
   - switch1

  gather_facts: yes # on recupere les infomations acctuel sur le switch 
mais fichier ne sera pas a jour ==> on recupere les facts avant de faire 
les changements

  vars:
 ansible_connection: network_cli
 ansible_network_os: ios
 ansible_user : "cisco"
 ansible_password : "cisco"
 ansible_become: yes
 ansible_become_method: enable
 ansible_become_password: "cisco"

  tasks:
- name: collect resources# on a plus besoin car on a deja tous 
recuprer, j'ai deja les infomrmations dans la base de donnees
  ios_facts:
gather_subset: all
gather_network_resources: vlans

- name: get all vlan configure on switch
  debug:
msg:
 # - "{{item.key}}"
  - "{{item.value}}"
  when : '"vlan_id" in item.key'
  register: result
  with_dict: "{{ansible_network_resources.vlans.item}}"
  loop: "{{ansible_network_resources.vlans}}"


- name: write list of vlans
  debug :
 msg : "{{ result }}"

-


from this file who i gather all facts of the device and and i make 
conditions

[image: Capture.PNG] 
 

-- 
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/228cee1c-d57a-4b08-8c9a-69755e58e2c8%40googlegroups.com.