76 lines
2.0 KiB
YAML
76 lines
2.0 KiB
YAML
---
|
|
- name: Create netstat security group
|
|
hosts: localhost
|
|
gather_facts: False
|
|
tasks:
|
|
- name: Create Security group
|
|
ec2_group:
|
|
ec2_access_key: "{{ access_key }}"
|
|
ec2_secret_key: "{{ secret_key }}"
|
|
name: "{{ netstat_security_group }}"
|
|
description: "Default security group"
|
|
region: "{{ region }}"
|
|
purge_rules_egress: false
|
|
purge_rules: false
|
|
vpc_id: "{{ vpc_id | default('') }}"
|
|
rules:
|
|
- proto: tcp
|
|
from_port: 22
|
|
to_port: 22
|
|
cidr_ip: 0.0.0.0/0
|
|
tags: netstat
|
|
|
|
|
|
- name: Create netstat
|
|
hosts: localhost
|
|
gather_facts: False
|
|
vars:
|
|
volumes:
|
|
- device_name: /dev/sda1
|
|
volume_size: 128
|
|
delete_on_termination: true
|
|
tasks:
|
|
- name: Launch instance
|
|
ec2:
|
|
id: "{{ netstat_instance_name }}"
|
|
ec2_access_key: "{{ access_key }}"
|
|
ec2_secret_key: "{{ secret_key }}"
|
|
key_name: "{{ awskeypair_name }}"
|
|
instance_tags:
|
|
Name: "{{ netstat_instance_name }}"
|
|
group: "{{ netstat_security_group }}"
|
|
instance_type: "{{ netstat_instance_type }}"
|
|
image: "{{ image }}"
|
|
count: "{{ netstat_count_instances }}"
|
|
wait: yes
|
|
region: "{{ region }}"
|
|
vpc_subnet_id: "{{ vpc_subnet_id | default('') }}"
|
|
volumes: "{{ volumes }}"
|
|
assign_public_ip: yes
|
|
register: ec2
|
|
- name: Add new instance to host group
|
|
add_host: hostname={{ item.public_ip }} groupname=launched
|
|
with_items: "{{ ec2.instances }}"
|
|
- name: Wait for SSH to come up
|
|
wait_for: host={{ item.public_ip }} port=22 delay=90 timeout=320 state=started
|
|
with_items: "{{ ec2.instances }}"
|
|
when: ec2.changed
|
|
tags: netstat
|
|
|
|
- name: Installing python
|
|
hosts: launched
|
|
gather_facts: False
|
|
user: ubuntu
|
|
become: True
|
|
vars:
|
|
ansible_ssh_port: 22
|
|
tasks:
|
|
- name: Install python
|
|
raw: test -e /usr/bin/python || (sudo apt -y update && sudo apt install -y python-minimal)
|
|
|
|
- name: EC2 access setup
|
|
hosts: netstat
|
|
become: True
|
|
roles:
|
|
- netstat-access
|