Hello,
Building new modules. Having problem when creating a key=value pair where “value” is an array.
I get the following error with the below config…
failed: [sw3] => (item={‘value’: {‘ipv4’: [‘10.100.1.1/24’, ‘10.200.1.1/24’]}, ‘key’: ‘swp2’}) => {“failed”: true, “item”: {“key”: “swp2”, “value”: {“ipv4”: [“10.100.1.1/24”, “10.200.1.1/24”]}}}
msg: this module requires key=value arguments ([‘name=swp2’, ‘ipv4=[10.100.1.1/24,’, ‘10.200.1.1/24]’, ‘applyconfig=yes’])
This is my variables file.
======== doesn’t work ======
interfaces:
sw3:
swp2:
ipv4:
- 10.100.1.1/24
- 10.200.1.1/24
If I change the variables file to say what is below… it works
===== this works =====
interfaces:
sw3:
swp2:
ipv4: “10.100.1.1/24,10.200.1.1/24”
I notice the problem is that the first configuration puts a space between the 2 elements in the array of IPs, and ‘shlex.split’ splits it at the space between the array elements. Any way around this? I like the first format much better. Plus now have to be super careful of white spaces in values with arrays. Find this kinda brittle.
My AnsibleModule argument call is like so, maybe I’m doing something wrong there?
module = AnsibleModule(
argument_spec=dict(
name=dict(required=True, type=‘str’),
bridgemems=dict(type=‘list’),
bondmems=dict(type=‘list’),
ipv4=dict(type=‘list’),
ipv6=dict(type=‘list’),
applyconfig=dict(required=True, type=‘str’)
),
mutually_exclusive=[
[‘bridgemems’, ‘bondmems’]
]
)
Thanks