loops over the registered variable to inspect the results in ansible -


i have ansible-playbook creates multiple ec2 security groups using with_items , register result.

here var file playbook:

---  ec2_security_groups:    - sg_name: nat_sg      sg_description: sg nat instance      sg_rules:        - proto: tcp          from_port: 22          to_port: 22          cidr_ip: 0.0.0.0/0     - sg_name: web_sg      sg_description: sg web instance      sg_rules:        - proto: tcp          from_port: 22          to_port: 22          cidr_ip: 0.0.0.0/0        - proto: tcp          from_port: 80          to_port: 80          cidr_ip: 0.0.0.0/0 

and here playbook creates ec2 security groups:

---   - name: ec2group | creating ec2 security group inside mentioned vpc    local_action:      module: ec2_group      name: "{{ item.sg_name }}"      description: "{{ item.sg_description }}"      region: "{{ vpc_region }}" # change aws region here      vpc_id: "{{ vpc.vpc_id }}" # vpc resgister name, can set manually      state: present      rules: "{{ item.sg_rules }}"    with_items: ec2_security_groups    register: aws_sg 

this works problem that, want group id of each group playbook has created next task, have tried failed:

- name: tag security group name   local_action:    module: ec2_tag    resource: "{{aws_sg.group_id}}"    region: "{{ vpc_region }}"    state: present    tags:      name: "{{vpc_name }}-group"   with_items: aws_sg.results 

can point me how can group_id each group register result. thanks

p.s: can value of group_id individual sg group like:

aws_sg.results[0].group_id , aws_sg.results[1].group_id etc

rtm. ansible set loop variable item each iteration.

aws_sg.results[0].group_id , aws_sg.results[1].group_id etc

assuming wrote above correct. need change aws_sg.group_id item.group_id:

- name: tag security group name   local_action:    module: ec2_tag    resource: "{{ item.group_id }}"    region: "{{ vpc_region }}"    state: present    tags:      name: "{{vpc_name }}-group"   with_items: aws_sg.results 

if doesn't work post output of task corrections:

- debug: msg="aws_sg= {{ aws_sg }}" 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -