Skip to content
This repository has been archived by the owner on Apr 10, 2022. It is now read-only.

Commit

Permalink
Add examples from April webinar
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansb committed Apr 26, 2018
1 parent c3deb81 commit 1d6f97a
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 0 deletions.
29 changes: 29 additions & 0 deletions inventory/prod.aws_ec2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugin: aws_ec2
boto_profile: [INSERT HERE]
cache: no
regions: # populate inventory with instances in these regions
- us-east-2
filters:
instance-state-name:
- running
- pending
# ignores 403 errors rather than failing
strict_permissions: False
hostnames:
- tag:DNS
- dns-name
- private-dns-name

# constructed features may be used to create custom groups
strict: False
keyed_groups:
- prefix: arch
key: architecture
- prefix: aws_az
key: placement.availability_zone
- prefix: aws_region
key: 'placement.availability_zone[:-1]'
- prefix: instance_type
key: instance_type
- prefix: tag
key: tags
59 changes: 59 additions & 0 deletions use_tower_callback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
- name: Set up aws connection info
set_fact:
aws_connection_info: &aws_connection_info
profile: "summit-18"
region: "{{ aws_region }}"
tower_job_secret: "INSERT SECRET HERE"
no_log: yes
- ec2_ami_facts:
# https://wiki.centos.org/Cloud/AWS collected 2018-01-10
<<: *aws_connection_info
filters:
architecture: x86_64
product-code: aw0evgkw8e5c1q413zgy5pjce
virtualization-type: hvm
root-device-type: ebs
name: 'CentOS Linux 7*'
register: amis
- set_fact:
latest_centos: >
{{ amis.images | sort(attribute='creation_date') | last }}
- name: Get VPC ID
ec2_vpc_net_facts:
filters:
cidr: 10.0.0.0/20
<<: *aws_connection_info
register: networks
- debug: var=networks
- ec2_vpc_subnet_facts:
<<: *aws_connection_info
filters:
vpc-id: '{{ networks.vpcs[0].id }}'
availability-zone: '{{ aws_region }}b'
register: nets
- debug: var=nets
- ec2_instance:
state: running
wait: false
image:
id: "{{ latest_centos.image_id }}"
<<: *aws_connection_info
key_name: "{{ demo_prefix }}-ssh-key"
instance_type: t2.large
name: summit-web-test
security_groups:
- '{{ demo_prefix }}-web'
- '{{ demo_prefix }}-ssh'
tower_callback:
host_config_key: "{{ tower_job_secret }}"
job_template_id: "configure-web-server"
tower_address: INSERT TOWER IP OR DNS HERE
network:
assign_public_ip: true
tags:
App: FakeNginx
vpc_subnet_id: '{{ nets.subnets[0].id }}'
register: result
- debug: var=result.instances[0].instance_id
- debug: var=result.instances[0].public_ip_address

0 comments on commit 1d6f97a

Please sign in to comment.