WIP
Guillaume Coré
2019-02-20 4c696fdeef27fade70564bcf3420309ad9d763cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
---
- import_playbook: ../../include_vars.yml
 
- name: Stop instances in all regions
  hosts: localhost
  gather_facts: false
  become: false
  environment:
    AWS_ACCESS_KEY_ID: "{{aws_access_key_id}}"
    AWS_SECRET_ACCESS_KEY: "{{aws_secret_access_key}}"
  tasks:
    - debug:
        msg: "Step 002 Post Infrastructure"
 
    - loop: "{{ target_regions | json_query('[].region') }}"
      loop_control:
        loop_var: _region
      ec2:
        instance_tags:
          "aws:cloudformation:stack-name": "{{ project_tag }}"
        state: stopped
        region: "{{ _region }}"
      # Shell equivalent
      # shell: >-
      #   aws ec2 stop-instances
      #   --region {{ _region }}
      #   --instance-ids $(
      #     aws ec2 describe-instances
      #     --filters "Name=tag:aws:cloudformation:stack-name,Values={{ project_tag }}
      #     --query Reservations[*].Instances[*].InstanceId
      #     --region {{_region }}
      #     --output text
      #   )