Created
September 17, 2018 20:34
-
-
Save hortonew/42cbe87abfa7846986c2115a87899532 to your computer and use it in GitHub Desktop.
Will allow you to set variables needed before dynamic inventory is run, allowing you to use ansible vault
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- name: Set env variables | |
hosts: localhost | |
connection: local | |
environment: | |
AWS_ACCESS_KEY_ID: "{{ AWS_ACCESS_KEY }}" | |
AWS_SECRET_ACCESS_KEY: "{{ AWS_SECRET_KEY }}" | |
tasks: | |
- name: Build AWS Inventory | |
command: "{{ ec2_py_location }} --list --refresh-cache" | |
register: aws_servers | |
- name: Create fact composed of all the new servers | |
set_fact: | |
new_aws_servers: "{{ aws_servers.stdout }}" | |
- name: Add hosts to in-memory inventory | |
add_host: | |
name: "{{ item }}" | |
groups: | |
- aws | |
with_items: "{{ new_aws_servers._meta.hostvars }}" | |
- name: Execute | |
hosts: aws | |
gather_facts: false | |
tasks: | |
- name: "Display the AWS servers this play will operate over" | |
debug: | |
msg: "{{inventory_hostname}}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment