move to local actions + check for remote file
This commit is contained in:
parent
2c86950121
commit
31e03ced63
34
site.yml
34
site.yml
|
@ -1,38 +1,48 @@
|
||||||
- hosts: tag_env_prod
|
- hosts: tag_env_prod
|
||||||
remote_user: ec2-user
|
remote_user: ec2-user
|
||||||
gather_facts: false # of no use
|
gather_facts: false # of no use
|
||||||
connection: local # prevent from trying to ssh into instance
|
#connection: local # prevent from trying to ssh into instance
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
target_group_arn: "arn:aws:elasticloadbalancing:eu-west-1:440357826049:targetgroup/TestAnsible/c2afd83500139d9a"
|
target_group_arn: "arn:aws:elasticloadbalancing:eu-west-1:440357826049:targetgroup/Target/ae7eb341ab1e701f"
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
- name: DEBUG
|
# - name: DEBUG
|
||||||
debug:
|
# debug:
|
||||||
msg: "{{ hostvars[inventory_hostname].instance_id }}"
|
# msg: "{{ hostvars[inventory_hostname].instance_id }}"
|
||||||
|
|
||||||
- name: Start instances
|
- name: Start instances
|
||||||
amazon.aws.ec2:
|
local_action:
|
||||||
|
module: amazon.aws.ec2
|
||||||
instance_ids: "{{ hostvars[inventory_hostname].instance_id }}"
|
instance_ids: "{{ hostvars[inventory_hostname].instance_id }}"
|
||||||
state: running
|
state: running
|
||||||
when: targetpractice == "true"
|
when: targetpractice == "true"
|
||||||
|
|
||||||
- name: Wait for instances to be reachable
|
- name: Wait for instances to be reachable
|
||||||
wait_for:
|
local_action:
|
||||||
|
module: wait_for
|
||||||
host: "{{ inventory_hostname }}"
|
host: "{{ inventory_hostname }}"
|
||||||
port: 22
|
port: 22
|
||||||
when: targetpractice == "true"
|
when: targetpractice == "true"
|
||||||
|
|
||||||
|
- name: 'check if example file exists'
|
||||||
|
stat:
|
||||||
|
path: /tmp/example-exists
|
||||||
|
when: blitz == "true" and targetpractice == "true"
|
||||||
|
register: example_exists_file
|
||||||
|
|
||||||
- name: Register targets in TargetGroup
|
- name: Register targets in TargetGroup
|
||||||
community.aws.elb_target:
|
local_action:
|
||||||
|
module: community.aws.elb_target
|
||||||
target_group_arn: "{{ target_group_arn }}"
|
target_group_arn: "{{ target_group_arn }}"
|
||||||
state: present
|
state: present
|
||||||
target_id: "{{ hostvars[inventory_hostname].instance_id }}"
|
target_id: "{{ hostvars[inventory_hostname].instance_id }}"
|
||||||
target_status: "unused"
|
target_status: "unused"
|
||||||
when: targetpractice == "true"
|
when: targetpractice == "true" and example_exists_file.stat.exists == True
|
||||||
|
|
||||||
- name: Deregister targets in TargetGroup
|
- name: Deregister targets in TargetGroup
|
||||||
community.aws.elb_target:
|
local_action:
|
||||||
|
module: community.aws.elb_target
|
||||||
target_group_arn: "{{ target_group_arn }}"
|
target_group_arn: "{{ target_group_arn }}"
|
||||||
state: absent
|
state: absent
|
||||||
target_id: "{{ hostvars[inventory_hostname].instance_id }}"
|
target_id: "{{ hostvars[inventory_hostname].instance_id }}"
|
||||||
|
@ -41,9 +51,9 @@
|
||||||
when: targetpractice == "false"
|
when: targetpractice == "false"
|
||||||
|
|
||||||
- name: Stop instances
|
- name: Stop instances
|
||||||
amazon.aws.ec2:
|
local_action:
|
||||||
|
module: amazon.aws.ec2
|
||||||
instance_ids: "{{ hostvars[inventory_hostname].instance_id }}"
|
instance_ids: "{{ hostvars[inventory_hostname].instance_id }}"
|
||||||
#instance_ids: "{{ play_hosts }}"
|
|
||||||
state: stopped
|
state: stopped
|
||||||
when: targetpractice == "false"
|
when: targetpractice == "false"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue