I am using the command module to run an AWS CLI command. The command has an argument in it that takes a space-delimited set of parameters, like this:
–subnets-mappings this that theother
When I issue the command on the command line, all the items in the lists are used. When I run the command via Ansible, only the last one in the list is used.
This is how I create the list of subnet mappings:
- set_fact:
snm: “{{ snm |default(‘’) ~ ‘SubnetId=’ ~ item.SubnetId ~ ‘,AllocationId=’ ~ item.AllocationId ~ ’ ’ }}”
with_items: “{{ nlb_subnet_mappings }}”
This is the command I am running:
- command: aws elbv2 create-load-balancer --name “{{ nlb_name }}” --type network --subnet-mappings “{{ snm }}” --region “{{ nlb_region }}”
register: nlb
Here is the “cmd” part returned by the command:
“cmd”: [“aws”, “elbv2”, “create-load-balancer”, “–name”, “ADFS-ext-nlb”, “–type”, “network”, “–subnet-mappings”, "SubnetId=subnet-c1580ba5,AllocationId=eipalloc-09644c10a5aac6a39 SubnetId=subnet-3cd85265,AllocationId=eipalloc-09c95f8e4f8e111b2 ", “–region”, “ap-southeast-2”]
Because of the way I build the command, there is a space at the end of the list, that is the only difference I can see. And I do build the lists as strings which are then passed as arguments - all the tags are one argument, all the subnets are one argument.
The Ansible command does work and issues no errors, but it only uses the last in the list of subnet mappings. If I do this on the command line, it DOES use both subnet mappings:
aws elbv2 create-load-balancer --name ADFS-ext-nlb --type network --subnet-mappings SubnetId=subnet-c1580ba5,AllocationId=eipalloc-09644c10a5aac6a39 SubnetId=subnet-3cd85265,AllocationId=eipalloc-09c95f8e4f8e111b2 --region ap-southeast-2
Any clues?
Regards, K.