linux - Using ansible launch configuration module ec2_lc and securitygroup names versus id -
i want accomplish following in aws ec2:
- create security groups using ansible module ec2_group.
- create launch configuration using ansible module ec2_lc , attach security group created earlier.
now, want use security group names instead of id's because want able recreate whole infrastructure ansible if needed.
recreating security groups cause id of group different. ec2_lc module accepts security group id's.
is there way can map security group id name?
i defining security groups this:
- name: create ec2 group ec2_group: name: "{{ item.name }}" description: "{{ item.description }}" vpc_id: "{{ item.vpc_id }}" region: "{{ item.region }}" state: present rules: "{{ item.rules }}" rules_egress: "{{ item.rules_egress }}" register: sg
the launch configuration code looks this:
- name: create launch configuration ec2_lc: region: "{{ item.region }}" name: "{{ item.name }}" image_id: "{{ item.image_id }}" key_name: "{{ item.key_name }}" security_groups: "{{ item.security_groups }}" # how can refer specific group_id based on group name? instance_type: "{{ item.instance_type }}" user_data: "{{ item.ec2_user_data }}" instance_profile_name: "{{ item.instance_profile_name }}" assign_public_ip: "{{ item.assign_public_ip }}"
with tribute this question, can try this:
- name: create launch configuration ec2_lc: ... security_groups: "{{ sg.results | selectattr('item.name','equalto',item) | join('',attribute='group_id') }}" ...
Comments
Post a Comment