Select instance from dynamic inventory based on tag #1

Closed
opened 2020-10-14 05:11:30 +00:00 by reel · 4 comments
reel commented 2020-10-14 05:11:30 +00:00 (Migrated from gitlab.com)

ansible-playbook example.yml -e targetpractice=true

- name: targetpractice
  hosts: tag_env_prod
  gather_facts: false
  roles:
    - targetpractice

Runtime variables targetpractice=true targetpractice=false

Find started/stopped instances with tag_env_prod.

  • If runtime variable targetpractice=true
    • instances state started
      • wait for instances to be reachable
    • register instances to target group
  • If runtime variable targetpractice=false
    • unregister instances from to target group
    • instances state stopped

The Ansible ELB and EC2 start permission are granted to the ansible controller. I'll still need to be able to execute shell tasks on the remote instances, like normal. I want to pick hosts based on tags.

`ansible-playbook example.yml -e targetpractice=true` ```yaml - name: targetpractice hosts: tag_env_prod gather_facts: false roles: - targetpractice ``` Runtime variables `targetpractice=true` `targetpractice=false` Find started/stopped instances with `tag_env_prod`. - If runtime variable `targetpractice=true` - instances state `started` - wait for instances to be reachable - register instances to target group - If runtime variable `targetpractice=false` - unregister instances from to target group - instances state `stopped` --- The Ansible ELB and EC2 start permission are granted to the ansible controller. I'll still need to be able to execute shell tasks on the remote instances, like normal. I want to pick hosts based on tags.
reel commented 2020-10-14 05:15:34 +00:00 (Migrated from gitlab.com)

changed the description

changed the description
reel commented 2020-10-20 23:02:29 +00:00 (Migrated from gitlab.com)

assigned to @vincentvdk

assigned to @vincentvdk
reel commented 2020-10-20 23:03:28 +00:00 (Migrated from gitlab.com)

mentioned in merge request !1

mentioned in merge request !1
vincentvdk commented 2020-10-24 11:16:45 +00:00 (Migrated from gitlab.com)

@reel Added an example that does what you are trying to accomplish.

@reel Added an example that does what you are trying to accomplish.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: stationgroup/ansible-target-practice#1
No description provided.