We’ve recently had to add multiple security groups to an ec2 instance, but based on the host group, it needs to be a different set of groups.
I see that you can do this by using an array list like so:
- name: launch
local_action:
module: ec2
region: us-west-2
keypair: xxxxx
group: [‘mygroup1’, ‘mygroup2’, ‘mygroup3’]
instance_type: t1.micro
image: ami-xxxxxx
wait: yes
wait_timeout: 3500
count: 2
instance_tags: ‘{“Name”:“stuff”}’
register: ec2
This will work fine when hard coded, but when i replace the list with a variable it does seem to detect the groups. What am I doing wrong?
- name: launch
local_action:
module: ec2
region: us-west-2
keypair: xxxxx
group: “{{ my_groups }}”
instance_type: t1.micro
image: ami-xxxxxx
wait: yes
wait_timeout: 3500
count: 2
instance_tags: ‘{“Name”:“stuff”}’
register: ec2
and set my_groups as:
my_groups: [‘mygroup1’, ‘mygroup2’, ‘mygroup3’]
My guess is it has something to do with the quotes but if i remove it, I get an YAML complaint, I’ve tried it a number of different ways without success. Any ideas?
Thanks!