[ansible-project] Find VLAN in a range of VLAN (930-932)
Using various methods, I can get a list of VLAN on a switch port. The list looks like the following: "vlans": "1,134,170,175,540,605,819-820,911-912,*930-932* ,945,952,955,959-960,1200-1201,1400" I would like to check to see if VLAN 931 is in the list. In this case its between 930-932 in the list. Is there a filter or function that I can use to see if its in the list? Is there some other way I can get this info? For a single VLAN number I can use when: 'item in vlans" if in a loop but 'in" looks for exact match. -- 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/7fbfa960-ecea-46a7-b3b1-660f56f912dbo%40googlegroups.com.
[ansible-project] using when inside and outside a loop
I want to do something like this below: - name: Create Simple list from Connection Dict set_fact: connections: "{{ connections | default([]) + [ { 'switchid': item.id, 'connectionid': item.connections[0].id } ] }}" when: item.connections #only want to create facts if connections exist loop: "{{ connections_result.json.0.switchPorts | flatten }}" when: connections_result is defined#depending on the host,connection_result.json may not be defined so need to check When I run the playbook, I get the following warning at the top [WARNING]: While constructing a mapping from /home/xxx/x.yml, line 245, column 5, found a duplicate dict key (when). Using last defined value only. Is there a way to get both when to work? -- 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/22ccb77e-eeea-4f09-92d8-13cee35fcb48%40googlegroups.com.
[ansible-project] Re: ios_ntp
Thanks this works. It would be very useful if the module would work like ios_system. If there is another DNS server in the switch config, ios_system removes it and makes sure only the server listed in the playbook remain. Where's the best place to put feature request? On Thursday, December 19, 2019 at 4:59:02 PM UTC-5, Spiro Mitsialis wrote: > > Has anyone used ios_ntp for Cisco IOS devices? Its new as of Ansible > v2.8. It works fine for 1 NTP server but how do you add a 2nd server. > I've tried the following and neither works. The 2nd method works for DNS > with ios_system but I guess this module is different. Anybody have it > working with multiple servers? > > - ios_ntp:server: 10.0.255.10server: 10.0.255.20 > > - ios_ntp:server: > - 10.0.255.10 > - 10.0.255.20 > > > -- 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/9ae6a99d-0815-4264-bdc1-201c86934be7%40googlegroups.com.
[ansible-project] ios_ntp
Has anyone used ios_ntp for Cisco IOS devices? Its new as of Ansible v2.8. It works fine for 1 NTP server but how do you add a 2nd server. I've tried the following and neither works. The 2nd method works for DNS with ios_system but I guess this module is different. Anybody have it working with multiple servers? - ios_ntp:server: 10.0.255.10server: 10.0.255.20 - ios_ntp:server: - 10.0.255.10 - 10.0.255.20 -- 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/778bb4ec-8e2a-412f-939f-a028cdd372d5%40googlegroups.com.
[ansible-project] Re: Accessing a dictionary item using a variable
Thanks Matt, That worked. I also found the following works (by trial and error) vlan_list["{{ vlan }}"] On Friday, December 13, 2019 at 10:29:35 AM UTC-5, Spiro Mitsialis wrote: > > I would like to access data in a dictionary by referencing a variable. I > have the following dict: > > "vlan_list": { >"1": { > "id": "1", > "name": "Management", > "status": "active" >}, >"2": { > "id": "2", > "name": "VLAN 2", > "status": "active" >}, >"3": { > "id": "3", > "name": "VLAN 3", > "status": "active" >} > } > > I also have a variable: > vlan: 2 > > > I'd like to do: > - debug: > var: vlan_list[vlan] > > This does not work? How can I user the variable "vlan" to get what is the > info for VLAN 2 in the dict vlan_list? > > > > Thanks > -- 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/3110181b-e6f4-4fd0-9bd0-f51d384100b3%40googlegroups.com.
[ansible-project] Accessing a dictionary item using a variable
I would like to access data in a dictionary by referencing a variable. I have the following dict: "vlan_list": { "1": { "id": "1", "name": "Management", "status": "active" }, "2": { "id": "2", "name": "VLAN 2", "status": "active" }, "3": { "id": "3", "name": "VLAN 3", "status": "active" } } I also have a variable: vlan: 2 I'd like to do: - debug: var: vlan_list[vlan] This does not work? How can I user the variable "vlan" to get what is the info for VLAN 2 in the dict vlan_list? Thanks -- 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/b75a64bd-c0d5-4aab-b190-51eb662975df%40googlegroups.com.
[ansible-project] json_query problem
I am reading a cmdb for location information and then I'm trying to match on the room number in order to get the locations id. The matching data is coming from a csv file. The play works for rooms that have letters in them but not if it is just numbers. I have not been able to figure out how to make it work. Result of cmdb lookup: "building_rooms_result.json": [ { "buildingName": "xxx Building", "city": "Montreal", "commonName": "", "country": "Canada", "createdAt": "2018-07-13T06:03:57.000Z", "fullName": "Downtown/xxx Building/Floor 0005/5106", "id": "ck2apr6yb002708380h9h7v3f", "loadedAt": "2019-10-28T17:48:28.000Z", "locationKey": "240|0005|5106", "locationType": "Classroom", "name": "5106", "parentId": "ck2aps8cl0e260838rofis4v6", }, { "buildingName": "xxx Building", "city": "Montreal", "commonName": "", "country": "Canada", "createdAt": "2018-07-13T06:06:32.000Z", "fullName": "Downtown/xxx Building/Floor 0004/4-TDUCT149", "id": "ck2apr6zh009g0838abhya4sj", "loadedAt": "2019-10-28T17:48:29.000Z", "locationKey": "240|0004|4-TDUCT149", "locationType": "Ducts", "name": "4-TDUCT149", "parentId": "ck2aps8br0diz08383bmk41yj", }, { "buildingName": "xxx Building", "city": "Montreal", "commonName": "", "country": "Canada", "createdAt": "2018-07-13T06:04:05.000Z", "fullName": "Downtown/xxx Building/Floor 0001/1-STAIR4", "id": "ck2apr6zq00bp0838h73fdrzf", "loadedAt": "2019-10-28T17:48:31.000Z", "locationKey": "240|0001|1-STAIR4", "locationType": "Stairs", "name": "1-STAIR4", "parentId": "ck2aptbfr0tr9083813gkgava", } ] This is the json_query I'm using. If I try to match on 1-STAIR4, it works. If I try to match on 5106 it does not match and I get the default na in the jacks_list. - name: create new list with all jack info set_fact: jacks_list: "{{ jacks_list | default([]) + [ { 'number': item.value.JACKNUMBER, 'locationId': building_rooms_result.json | json_query(query_locat) | default('na', True), 'telcoId': telco_result.json.0.id }] }}" vars: query_locat: '[?name==`{{ item.value.ROOMNUMBER | string }}`].id | [0]' loop: "{{ connections.dict | dict2items }}" The csv import data looks like: ok: [127.0.0.1] => (item={'key': u'240D005082', 'value': {u'ACTIVEDATE': u '01-Dec-00', u'SHUT': u'0', u'LASTNAME': u'', u'VLAN': u'71', u'ROOMNUMBER': u'5102', u'ROOMID': u'240D', u'PORT_TYPE': u'GigabitEthernet1/0/37', u 'ACTIVEBY': u'', u'PORT_GROUP': u'eng', u'DEPTNAME': u'Department of ', u 'PORT_NO': u'1/0/37', u'FIRSTNAME': u'S', u'AUTHORIZEDBY': u'So, Mr.', u 'SPEED': u'auto', u'FOAPAL': u'', u'DUPLEX': u'auto', u'DEPTCODE': u'00156', u'BUILDCODE': u'000240', u'SWITCHNAME': u'xxx-5050-sw1', u'JACKNUMBER': u '240D005082', u'F_ROOMCODE': u''}}) ok: [127.0.0.1] => (item={'key': u'240D005028', 'value': {u'ACTIVEDATE': u '01-Aug-19', u'SHUT': u'0', u'LASTNAME': u'IT', u'VLAN': u'67', u 'ROOMNUMBER': u'5110', u'ROOMID': u'240D', u'PORT_TYPE': u 'GigabitEthernet1/0/34', u'ACTIVEBY': u'mary', u'PORT_GROUP': u'eng', u 'DEPTNAME': u'Department ', u'PORT_NO': u'1/0/34', u'FIRSTNAME': u'ECE', u 'AUTHORIZEDBY': u', Mr.', u'SPEED': u'auto', u'FOAPAL': u'00', u'DUPLEX' : u'auto', u'DEPTCODE': u'00156', u'BUILDCODE': u'000240', u'SWITCHNAME': u 'xxxr-5050-sw1', u'JACKNUMBER': u'240D005028', u'F_ROOMCODE': u'5110'}}) ok: [127.0.0.1] => (item={'key': u'240D005280', 'value': {u'ACTIVEDATE': u'08-Nov-06', u'SHUT': u'0', u'LASTNAME': u'', u'VLAN': u'820', u'ROOMNUMBER': u'5080HLWY', u'ROOMID': u'240D', u'PORT_TYPE': u'GigabitEthernet3/0/35', u'ACTIVEBY': u'csr3', u'PORT_GROUP': u'noc', u'DEPTNAME': u'Network', u'PORT_NO': u'3/0/35', u'FIRSTNAME': u'Wireless', u'AUTHORIZEDBY': u'NOR', u'SPEED': u'auto 10 100', u'FOAPAL': u'00', u'DUPLEX': u'auto', u'DEPTCODE': u'00043', u'BUILDCODE': u'000240', u'SWITCHNAME': u'xxxr-5050-sw1', u'JACKNUMBER': u'240D005280', u'F_ROOMCODE': u''}}) >From the above only 5080HLWY will match to a record in locations. Looks like its an issue of string to int but I cant seem to figure out how and where to convert it. I am using the read_csv Ansible module to read the csv file. -- 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/69a5649e-4ed6-4b52-a4d6-8df4dbcc813b%40googlegr
[ansible-project] Re: Create a Dict key from a variable
Thanks Vladamir, Works great! Wish there was some good docs out there. On Thursday, October 10, 2019 at 1:12:01 PM UTC-4, Spiro Mitsialis wrote: > > Hi, > > I hope I am using the right terminology here. > I'm trying to modify some cisco_ios facts. I know how to use combine to > merge the two together. I'm having problems creating a list/dict that I > can use to merge into the original dict > The playbook is passed a variable called "port". What I would like to > create a fact as below > > set_fact: > temp_interface: > "{{ port }}": > name: "{{ port }}" > description: free > status: shutdown > > This above does not work. As an example port = GigabitEthernet1/0/10 > > The result from above is: > > TASK [debug] > *** > ok: [switch-poc-sw8.gw.mcgill.ca] => { > "temp_interface": { > "{{ port_id }}": { > "description": "free", > "name": "GigabitEthernet1/0/10", > "status": "shutdown" > > } > } > } > > How can this be accomplished. > Thanks > -- 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/22009e21-4da2-42d2-bb5f-c7064900a164%40googlegroups.com.
[ansible-project] Create a Dict key from a variable
Hi, I hope I am using the right terminology here. I'm trying to modify some cisco_ios facts. I know how to use combine to merge the two together. I'm having problems creating a list/dict that I can use to merge into the original dict The playbook is passed a variable called "port". What I would like to create a fact as below set_fact: temp_interface: "{{ port }}": name: "{{ port }}" description: free status: shutdown This above does not work. As an example port = GigabitEthernet1/0/10 The result from above is: TASK [debug] *** ok: [switch-poc-sw8.gw.mcgill.ca] => { "temp_interface": { "{{ port_id }}": { "description": "free", "name": "GigabitEthernet1/0/10", "status": "shutdown" } } } How can this be accomplished. Thanks -- 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/a6d09ac0-2f43-4004-a330-59abfe3134f2%40googlegroups.com.
[ansible-project] Re: How to use variables from one task in another task
May not be exactly what you are looking for but you can have a new task with same variables but you use delegate_to another host. - name: "create a file in the directory" file: path: "/home/ansible_user/from_controller4/file_name" state: touch when: result is succeeded delegate_to: another_host On Friday, September 20, 2019 at 3:37:20 AM UTC-4, Srinivas Naram wrote: > > Hello Ansible Gurus, > > I am new to Ansible and trying to get my hands dirty on playbooks. I wrote > an yaml file to use a variable from one host tasks to another. Here is my > code ( logically this code may not make sense in real world, I am trying to > understand features in Ansible ) > > > > --- > - > hosts: modified_user1 > tasks: > - > name: "test connection" > ping: > register: result > - > debug: > var: result > when: result is succeeded > - > file: >path: "/home/ansible_user/from_controller3/file_name" >state: touch > when: result is succeeded > > - > hosts: modified_user2 > tasks: > - name: "create a file in the directory" > file: >path: "/home/ansible_user/from_controller4/file_name" >state: touch > when: result is succeeded > - > debug: >var: result > > > > Is there a provision to pass 'result' variable to second host ? > > -- 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/b0ef5fea-8fe8-400f-8e6c-b5509ecc4dd1%40googlegroups.com.
[ansible-project] calling a role and passing it a different host
I have playbook that is running for a network switch. From within this playbook, I want to call a role which will run a IOS Ansible module but the host should be a different device (host). The different device is its upstream neighbor which the first playbook gets doing a URI call to a database. I dont have the information before the URI call. Both devices are listed in my hosts inventory file. I have tried listing the new host in the role/vars/main.yml file but it still sees the first network switch. hosts: xxx I have also tried specifying hosts when calling the role: - name: call manage trunk vlans include_role: name: manage_trunk_vlans vars: hosts: burnside-lab-srp.gw.mcgill.ca -- 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/6366b0a4-3cbb-41b2-8ea6-fc162e9875fc%40googlegroups.com.
[ansible-project] Splitting a List into chunks
Hi, I have a list of 200+ items (showing sample below). I need to update a database with these records using the URI module. The backend API only supports 100 records at at time. How can I loop through the URI module with 100 records at a time. I was thinking of using json_query and doing slicing as per the JMEPath docs but cant find any examples of the syntax for Ansible. If using the json_quere, I would need some sort of variable in the slice. - name: Add/Update switchport in cmdb uri: url: https://{{ cmdb }}/{{ switchports }}/batchUpsert method: PUT validate_certs: no body_format: json body: '{{ new_list | json_query([:100] }}' register: batchupsert_result loop:??? "new_list": [ { "description": null, "id": "cjzu47wi6000301yu0dse3q53", "lastSeenDate": "2019-09-05 10:06:42", "mediaType": "access", "name": "GigabitEthernet2/1/1", "poeEnabledInd": true, "portDuplexModeId": "cjzodb84y001201fmbox90ygt", "portFastInd": true, "portSpeedId": "cjzodk5zx001301fmac9u54oc", "securityShutdownInd": "false", "status": "down", "voiceInd": false }, { "description": null, "id": "cjzu4jsq1000u01yu9cw4a9h7", "lastSeenDate": "2019-09-05 10:06:42", "mediaType": "access", "name": "GigabitEthernet2/0/9", "poeEnabledInd": true, "portDuplexModeId": "cjzodb84y001201fmbox90ygt", "portFastInd": true, "portSpeedId": "cjzodk5zx001301fmac9u54oc", "securityShutdownInd": "false", "status": "down", "voiceInd": false }, { "description": null, "id": "cjzu4jxhc000v01yuf9c7atd3", "lastSeenDate": "2019-09-05 10:06:42", "mediaType": "access", "name": "TenGigabitEthernet2/1/3", "poeEnabledInd": true, "portDuplexModeId": "cjzodb84y001201fmbox90ygt", "portFastInd": true, "portSpeedId": "cjzodk5zx001301fmac9u54oc", "securityShutdownInd": "false", "status": "shutdown", "voiceInd": false }, { "description": null, "id": "cjzu48c09000401yu1o443fuq", "lastSeenDate": "2019-09-05 10:06:42", "mediaType": "access", "name": "TenGigabitEthernet2/1/4", "poeEnabledInd": true, "portDuplexModeId": "cjzodb84y001201fmbox90ygt", "portFastInd": true, "portSpeedId": "cjzodk5zx001301fmac9u54oc", "securityShutdownInd": "false", "status": "down", "voiceInd": false } ] -- 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/5e0510be-e7bf-4b3c-b40f-829c953f75d8%40googlegroups.com.
[ansible-project] Adding a Fact to a dict for Cisco Interf.
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.
[ansible-project] Variable within variable
I have the following and there may be several vlans per switch. "cisco_ios.vlans": { "35": { "id": "35", "mtu": "1500", "name": "CC_internal_subnet_35", "ports": [ "GigabitEthernet1/0/1", "GigabitEthernet1/0/2", "GigabitEthernet1/0/20" ], "status": "active" }, "499": { "id": "499", "mtu": "1500", "name": "Lync_VoIP_Burnside1", "ports": [ "" ], "status": "active" } } I want to be able to reference the data in here. Example, I am looking to loop through al *.ports. I'm trying to do the following which does not work vars: old_vlan: 35 new_vlan: 45 - name: Change vlan old_vlan to new_vlan for all ports in list debug: msg: "Old VLAN is {{ old_vlan }} and port {{ item }} needs to be changed" loop: '{{ cisco_ios.vlans["{{ old_vlan }}"].ports }}' The following work: loop: '{{ cisco_ios.vlans["35"].ports }}' but how do I substitute 35 with the variable old_vlan which contains 35? -- 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/cd37806b-f4ce-4313-9043-6a33b1d1f638%40googlegroups.com.
[ansible-project] Re: Network stack
Hi, Its based on IP address so a stack is one device from Ansible's view. Spiro On Tuesday, May 7, 2019 at 11:08:12 AM UTC-4, rajthecomputerguy wrote: > > Hi Team, > > Is network stack consider as single node license in ansible tower? for eg > I have network stack contains 4 switches. I need to understand whether have > to buy license for four switches or single license is enough. > > thanks > Pushparaj > -- 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 post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/1fe6f182-03c9-4b14-b38f-aa385d68bf9b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Change a dictionary within a loop
I am trying to edit ansible_facts created by network-engine inside a loop but cannot figure out the syntax. I have a bunch of VLANs as a dict. ``` ok: [burnside-lab-srp.gw.mcgill.ca] => { "ansible_facts": { "cisco_ios": { "vlans": { "1": { "id": "1", "mtu": "1500", "name": "default", "ports": [ "TenGigabitEthernet2/1/16", "GigabitEthernet101/1/0/15" ], "status": "active" }, "1172": { "id": "1172", "mtu": "1500", "name": "test-macsec", "ports": [ "TenGigabitEthernet1/3/1" ], "status": "active" }, In my playbook, I call another play since I cannot loop with "block". ```- name: Check if VLAN exists in IPAM and check if name the same include: router_check_vlan_name.yml with_dict: "{{ cisco_ios.vlans }}" router_check_vlan_name.yml looks up the name in IPAM and tries to change the fact's name: ``` - name: Get IPAM VLAN domain info for VLAN using EIP API uri: url: https://ipam/rest/vlmvlan_list/WHERE/vlmdomain_name='{{ router }}'+AND+vlmvlan_vlan_id='{{ item.value.id }}' method: GET validate_certs: no return_content: yes timeout: 60 headers: X-IPM-Username: "{{ ipam_username }}" X-IPM-Password: "{{ ipam_password }}" register: result - name: show result of API debug: msg: "VLAN is {{ result.json[0].vlmvlan_vlan_id }} and name is {{ result.json[0].vlmvlan_name }}" verbosity: 1 - name: Check if VLAN was found int IPAM; if not generate error block: - debug: msg: "VLAN {{ item.value.id }} was NOT FOUND IN IPAM" - set_fact: vlans_to_alert_for: "{{ vlans_to_alert_for }},{{ item.value.id }}" when: result.json[0].vlmvlan_name == '' - name: Check if the VLAN names match if they do not generate error block: - name: Change cisco_ios.vlan name to match IPAM name set_fact: cisco_ios: vlans:* "{{ item.value.id }}":* name: "{{ result.json[0].vlmvlan_name }} - debug: msg: "VLAN {{ item.value.id }}, Router VLAN name: {{ item.value.name }} and IPAM VLAN Name: {{ result.json[0].vlmvlan_name }} DO NOT match IPAM: fixing" when: - item.value.name != result.json[0].vlmvlan_name - result.json[0].vlmvlan_name != '' I cannot figure out the syntax to get this to work. "{{ item.value.id }}" is seen exactly like this. I do not see the value in the dicts. ``` TASK [Change cisco_ios.vlan name to match IPAM name] ** task path: /home/smitsi1/tower-network-playbooks/router_check_vlan_name.yml:33 ok: [burnside-lab-srp.gw.mcgill.ca] => { "ansible_facts": { "new_vlans": { "{{ item.value.id }}": { "name": "ZERO-TOUCH-DHCP" } } }, "changed": false } What I'd like to see is the original list above with the name modified. I'd appreciate any help. Thanks, -- 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 post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/370ff4d9-9813-46e6-816a-21362150a4d8%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Re: using when something > variable
Thanks, it worked. -- 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 post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/876cf7ee-d500-4fc4-bf23-c6e7aea61f81%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] using when something > variable
I have a playbook that performs a command on a router and then parses the output. So far no problem. I'm then trying to check if any of the variables back from the parser are >= threshold. The threshold is defined as a variable in the playbook. No problem with it. vars: threshold: 90 tcam_full: False Although I do not get any error messages the following is never true, even when it should be. Is there a way to make it work? - name: check ACL Mask set_fact: tcam_full: true when: item.acl_mask >= "{{ threshold }}" with_items: "{{ tcam.tcam_resources }}" If I add a threshold manually like below it works fine. I have several of these statements and would rather not hard code the threshold value - name: check ACL Entries set_fact: tcam_full: true when: item.acl_ent >= 90 with_items: "{{ tcam.tcam_resources }}" Finally, I also get a warning message about using jinja2 templates with a when statement. How should I be doing it? I've had similar messages when checking if a {{ variable }} == something. [WARNING]: when statements should not include jinja2 templating delimiters 36 such as {{ }} or {% %}. Found: item.acl_mask >= "{{ threshold }}" -- 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 post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/3520d313-7ad3-4770-8584-0255f5ecc59d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Re: Cisco Show Power Inline command with Ansible
Hi, I wrote a parser that will take the output and add it to a dictionary. I've tested it on a C3850 but you can try it and see if it works on your device. You may need to modify it to work with your switch (Nexus?). If your interested I'll put it up on GitHub and provide the link. Spiro On Thursday, January 31, 2019 at 4:36:17 PM UTC-5, Michael Sawires wrote: > > Hi There, > > I have a request to match a specific line in output of show power inline > command below, mainly I need to extract line number 4 from below: > > DP-M-R4-C9K#sh power inline > > Module Available Used Remaining > (Watts) (Watts)(Watts) > -- - - > 1 490.00.0 490.0 > Interface Admin Oper Power Device Class Max > (Watts) > - -- -- --- --- - > Tw1/0/1 auto off0.0 n/a n/a 60.0 > Tw1/0/2 auto off0.0 n/a n/a 60.0 > Tw1/0/3 auto off0.0 n/a n/a 60.0 > Tw1/0/4 auto off0.0 n/a n/a 60.0 > Tw1/0/5 auto off0.0 n/a n/a 60.0 > Tw1/0/6 auto off0.0 n/a n/a 60.0 > Tw1/0/7 auto off0.0 n/a n/a 60.0 > Tw1/0/8 auto off0.0 n/a n/a 60.0 > Tw1/0/9 auto off0.0 n/a n/a 60.0 > Tw1/0/10 auto off0.0 n/a n/a 60.0 > Tw1/0/11 auto off0.0 n/a n/a 60.0 > Tw1/0/12 auto off0.0 n/a n/a 60.0 > Tw1/0/13 auto off0.0 n/a n/a 60.0 > Tw1/0/14 auto off0.0 n/a n/a 60.0 > Tw1/0/15 auto off0.0 n/a n/a 60.0 > Interface Admin Oper Power Device Class Max > (Watts) > - -- -- --- --- - > Tw1/0/16 auto off0.0 n/a n/a 60.0 > Tw1/0/17 auto off0.0 n/a n/a 60.0 > Tw1/0/18 auto off0.0 n/a n/a 60.0 > Tw1/0/19 auto off0.0 n/a n/a 60.0 > Tw1/0/20 auto off0.0 n/a n/a 60.0 > Tw1/0/21 auto off0.0 n/a n/a 60.0 > Tw1/0/22 auto off0.0 n/a n/a 60.0 > Tw1/0/23 auto off0.0 n/a n/a 60.0 > Tw1/0/24 auto off0.0 n/a n/a 60.0 > Tw1/0/25 auto off0.0 n/a n/a 60.0 > Tw1/0/26 auto off0.0 n/a n/a 60.0 > Tw1/0/27 auto off0.0 n/a n/a 60.0 > Tw1/0/28 auto off0.0 n/a n/a 60.0 > Tw1/0/29 auto off0.0 n/a n/a 60.0 > Tw1/0/30 auto off0.0 n/a n/a 60.0 > Tw1/0/31 auto off0.0 n/a n/a 60.0 > Tw1/0/32 auto off0.0 n/a n/a 60.0 > Tw1/0/33 auto off0.0 n/a n/a 60.0 > Tw1/0/34 auto off0.0 n/a n/a 60.0 > Tw1/0/35 auto off0.0 n/a n/a 60.0 > Tw1/0/36 auto off0.0 n/a n/a 60.0 > Te1/0/37 auto off0.0 n/a n/a 60.0 > Interface Admin Oper Power Device Class Max > (Watts) > - -- -- --- --- - > Te1/0/38 auto off0.0 n/a n/a 60.0 > Te1/0/39 auto off0.0 n/a n/a 60.0 > Te1/0/40 auto off0.0 n/a n/a 60.0 > Te1/0/41 auto off0.0 n/a n/a 60.0 > Te1/0/42 auto off0.0 n/a n/a 60.0 > Te1/0/43 auto off0.0 n/a n/a 60.0 > Te1/0/44 auto off0.0 n/a n/a 60.0 > Te1/0/45 auto off0.0 n/a n/a 60.0 > Te1/0/46 auto off0.0 n/a n/a 60.0 > Te1/0/47 auto off0.0 n/a n/a 60.0 > Te1/0/48 auto off0.0 n/a n/a 60.0 > > Assistance is appreciated. > > Michael > -- 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 post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/m
[ansible-project] Re: Escaping - and / in dictionary name
Thanks, This works. I tried all sorts of combination with square brackets but not this. Works for following as well: var: ansible_facts.cisco_ios.interfaces['*GigabitEthernet1/1/1']* -- 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 post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/0675a42a-f381-454a-8e51-f178c0ec8a9b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Escaping - and / in dictionary name
Hi, I'm calling the ansible-network.cisco_cli parser to parse the show interface of a switchport. It returns the following: "ansible_facts": { "cisco_ios": { "interfaces": { "GigabitEthernet1/0/1": { "*admin-status*": "enabled", "counters": { "in-broadcast-pkts": "67706", "in-multicast-pkts": null, "in-octets": "4483218", "in-unicast-pkts": "1680087045", "out-errors": "0", "out-octets": "9071817", "out-unicast-pkts": "5628651075" }, "description": "test port 802.1x", "enabled": true, "mtu": "9000", "name": "GigabitEthernet1/0/1", "oper-status": "down", "type": "Gigabit Ethernet" } } } In my playbook I'm trying to display the admin-status which has a dash and is not allowed in a variable name. This comes from the parser. I get an error each time - name: display output debug: var: ansible_facts.cisco_ios.interfaces["{{ interface | lower | regex_replace('gi','GigabitEthernet') }}"].*admin-status * The play works if I check counters: - name: display output debug: var: ansible_facts.cisco_ios.interfaces["{{ interface | lower | regex_replace('gi','GigabitEthernet') }}"].*counters* So how can I escape the - in the admin-status? Once this works I will use it with a when statement: when: ansible_facts.cisco_ios.interfaces["{{ interface | lower | regex_replace('gi','GigabitEthernet') }}"].admin-status == enabled I have similar problem if I try to do the following, so I'm hoping that the same escape will work with the /: - name: display output debug: var: ansible_facts.cisco_ios.interfaces.*GigabitEthernet1/1/1* Thanks, Spiro -- 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 post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/31be9ff8-32cd-467d-ad65-faebece7fa2f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: [ansible-project] Looping through a dictionary
Thanks it worked. I get all this extra debug info. Is there a way to display only the 2nd line: "msg": "Name is Vlan1 and status is administratively down"? TASK [display output] ** ok: [burnside-poc-sw8.gw.mcgill.ca] => (item={'status': u'administratively down', 'protocol': u'down', 'name': u'Vlan1', 'ok': u'YES', 'ipaddress': u'unassigned', 'method': u'NVRAM'}) => { "msg": "Name is Vlan1 and status is administratively down" } ok: [burnside-poc-sw8.gw.mcgill.ca] => (item={'status': u'up', 'protocol': u'up', 'name': u'Vlan99', 'ok': u'YES', 'ipaddress': u'172.31.35.8', 'method': u'NVRAM'}) => { "msg": "Name is Vlan99 and status is up" } ok: [burnside-poc-sw8.gw.mcgill.ca] => (item={'status': u'administratively down', 'protocol': u'down', 'name': u'Vlan252', 'ok': u'YES', 'ipaddress': u'unassigned', 'method': u'NVRAM'}) => { "msg": "Name is Vlan252 and status is administratively down" } > int_output.interfaces is a list and you need to use with_items. > - name: display output debug: var: "Name is {{ item.name }} and status is {{ item.status }}" with_items: "{{ int_output.interfaces }}" > > > -- Kai Stian Olstad > > -- 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 post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/64d55e80-d77c-42c7-bc44-d126d99086f2%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[ansible-project] Looping through a dictionary
Hi, I have a dictionary and I need to set through it to extract data but cannot figure out how to do it. Dictionary looks like: "int_output": { "interfaces": [ { "ipaddress": "unassigned", "method": "NVRAM", "name": "Vlan1", "ok": "YES", "protocol": "down", "status": "administratively down" }, { "ipaddress": "172.31.35.8", "method": "NVRAM", "name": "Vlan99", "ok": "YES", "protocol": "up", "status": "up" }, { "ipaddress": "unassigned", "method": "NVRAM", "name": "Vlan252", "ok": "YES", "protocol": "down", "status": "administratively down" } ] } I've tried using with_item and now trying with with_dict but cannot figure out how to make it work. ... - name: display output debug: var: "Name is {{ item.name }} and status is {{ item.status }}" with_dict: "{{ int_output.interfaces[0] }}" The above gives: TASK [display output] *** fatal: [burnside-poc-sw8.gw.mcgill.ca]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was : 'dict object' has no attribute 'name'\n\nThe error appears to have been in '/show_int_brief.yml': line 32, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n \n- name: display output\n ^ here\n"} Also tried: - name: display output debug: var: "Name is {{ item.name }} and status is {{ item.status }}" with_dict: int_output.interfaces[0] Above gives: TASK [display output] ** fatal: [burnside-poc-sw8.gw.mcgill.ca]: FAILED! => {"msg": "with_dict expects a dict"} Any ideas good be appreciated. -- 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 post to this group, send email to ansible-project@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/d2f0f045-3228-40e9-ada1-d5f0dc5dd7a4%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.