mirror of
https://github.com/trailofbits/algo.git
synced 2025-06-06 15:13:56 +02:00
EC2 dynamic enventory. Fixes #73
This commit is contained in:
parent
5cbf125202
commit
f7da2e3888
3 changed files with 45 additions and 0 deletions
|
@ -58,3 +58,10 @@ SSH_keys:
|
|||
comment: algo@ssh
|
||||
private: configs/algo.pem
|
||||
public: configs/algo.pem.pub
|
||||
|
||||
dynamic_inventory_groups:
|
||||
- azure
|
||||
- digitalocean
|
||||
- ec2
|
||||
- gce
|
||||
- local
|
||||
|
|
|
@ -12,3 +12,14 @@
|
|||
|
||||
- name: Change mode for the SSH private key
|
||||
local_action: file path=configs/algo.pem mode=0600
|
||||
|
||||
- name: Ensure the dynamic inventory exists
|
||||
blockinfile:
|
||||
dest: configs/inventory.dynamic
|
||||
marker: "# {mark} ALGO MANAGED BLOCK"
|
||||
create: yes
|
||||
block: |
|
||||
[algo:children]
|
||||
{% for group in dynamic_inventory_groups %}
|
||||
{{ group }}
|
||||
{% endfor %}
|
||||
|
|
|
@ -96,6 +96,7 @@
|
|||
region: "{{ region }}"
|
||||
instance_tags:
|
||||
name: "{{ aws_server_name }}"
|
||||
Environment: Algo
|
||||
exact_count: 1
|
||||
count_tag:
|
||||
name: "{{ aws_server_name }}"
|
||||
|
@ -115,3 +116,29 @@
|
|||
|
||||
- set_fact:
|
||||
cloud_instance_ip: "{{ ec2.tagged_instances[0].public_ip }}"
|
||||
|
||||
- name: Get EC2 instances
|
||||
ec2_remote_facts:
|
||||
aws_access_key: "{{ aws_access_key | default(lookup('env','AWS_ACCESS_KEY_ID'))}}"
|
||||
aws_secret_key: "{{ aws_secret_key | default(lookup('env','AWS_SECRET_ACCESS_KEY'))}}"
|
||||
region: "{{ region }}"
|
||||
filters:
|
||||
instance-state-name: running
|
||||
"tag:Environment": Algo
|
||||
register: algo_instances
|
||||
|
||||
- name: Ensure the group ec2 exists in the dynamic inventory file
|
||||
lineinfile:
|
||||
state: present
|
||||
dest: configs/inventory.dynamic
|
||||
line: '[ec2]'
|
||||
|
||||
- name: Populate the dynamic inventory
|
||||
lineinfile:
|
||||
state: present
|
||||
dest: configs/inventory.dynamic
|
||||
insertafter: '\[ec2\]'
|
||||
regexp: "^{{ item.public_ip_address }}.*"
|
||||
line: "{{ item.public_ip_address }}"
|
||||
with_items:
|
||||
- "{{ algo_instances.instances }}"
|
||||
|
|
Loading…
Add table
Reference in a new issue