This being my first time posting, I messed some things up. Hopefully I can correct that. By correcting the question and providing more info.
I am needing to use a mac address as a variable. I have tasks that gather information from a client on a network, mac, ip and name. I need to use each one of them as variables, and i can figure out how to use the ip and name, but not the mac.
I have tried to use set_fact, but i am not get it to loop over the clients pulled to be able to use as a variable. Any help would be appreciated.
- name: Get Vlan 30 Clients
networks_clients_info:
meraki_api_key: "{{ MERAKI_KEY }}"
vlan: 30
networkId: "{{ store_id.msg[0] }}"
recentDeviceConnections: Wired
os: Windows
register: client_list
- debug:
msg: "{{client_list}}"
- name: Get Client Info
debug:
msg: "{{ client_list |
community.general.json_query(query) }}"
vars:
query: " meraki_response[*].
{mac: mac, ip: ip, name: description} "
register: client_info
- name: Get MacAddress
vars:
mac_name: client_mac
mac_value: "{{ client_list |
community.general.json_query('meraki_response[].mac')
}}"
set_fact:
"{{ mac_name }}": "{{ mac_value }}"
- debug:
msg: "client_mac = {{ client_mac }}"
- name: Update a VLAN.
networks_appliance_vlans:
meraki_api_key: "{{ MERAKI_KEY }}"
networkId: "{{ store_id.msg[0] }}"
state: present
vlanId: 30
fixedIpAssignments:
22:33:44:55:66:77: <-- "{{client_mac}}
ip: 1.2.3.4 <-- "{{client_ip}}"
name: Some client name <-- "{{cleint_name}}"
Output:
ok: [localhost] => {
"msg": {
"changed": false,
"failed": false,
"meraki_response": [
{
"adaptivePolicyGroup": ,
"description": "some-device1",
"deviceTypePrediction": null,
"firstSeen": "",
"groupPolicy8021x": null,
"id": "",
"ip": "10.0.0.1",
"ip6": null,
"ip6Local": "",
"lastSeen": "",
"mac": "00:00:00:00:00:01",
"manufacturer": "",
"notes": ,
"os": "",
"pskGroup": null,
"recentDeviceConnection": "",
"recentDeviceMac": "",
"recentDeviceName": "",
"recentDeviceSerial": "",
"smInstalled": false,
"ssid": null,
"status": "",
"switchport": null
"user": null,
"vlan": "30",
"wirelessCapabilities": ""
},
{
"adaptivePolicyGroup": null,
"description": "some-device2",
"deviceTypePrediction": null,
"firstSeen": "",
"groupPolicy8021x": null,
"id": "",
"ip": "10.0.0.2",
"ip6": null,
"ip6Local": "",
"lastSeen": "",
"mac": "00:00:00:00:00:02",
"manufacturer": "",
"notes": null,
"os": "",
"pskGroup": null,
"recentDeviceConnection": "",
"recentDeviceMac": "",
"recentDeviceName": "",
"recentDeviceSerial": "",
"smInstalled": false,
"ssid": null,
"status": "Online",
"switchport": null,
"user": null,
"vlan": "30",
"wirelessCapabilities": ""
}
],
"result": ""
}
}
TASK [Get Client Info] *************************
ok: [localhost] => {
"msg": [
{
"ip": "10.0.0.1",
"mac": "00:00:00:00:00:01",
"name": "some-device1"
},
{
"ip": "10.0.0.2",
"mac": "00:00:00:00:00:02",
"name": "some-device2"
}
]
}
TASK [Get MacAddress] ************************
ok: [localhost]
TASK [debug] *******************
ok: [localhost] => {
"msg": "client_mac = ['00:00:00:00:00:01', '00:00:00:00:00:02']"
}
For example, given the data for testing
The below expressions
give what you (probably) want
Example of a complete playbook for testing