99 lines
2.5 KiB
YAML
99 lines
2.5 KiB
YAML
---
|
|
- name: Create mining 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: mining-security
|
|
description: "Default security group"
|
|
region: "{{ region }}"
|
|
# purge_rules_egress: true
|
|
# purge_rules: true
|
|
rules:
|
|
- proto: tcp
|
|
from_port: 22
|
|
to_port: 22
|
|
cidr_ip: 0.0.0.0/0
|
|
- proto: tcp
|
|
from_port: 8545
|
|
to_port: 8545
|
|
cidr_ip: 0.0.0.0/0
|
|
- proto: tcp
|
|
from_port: 30303
|
|
to_port: 30303
|
|
cidr_ip: 0.0.0.0/0
|
|
- proto: udp
|
|
from_port: 30303
|
|
to_port: 30303
|
|
cidr_ip: 0.0.0.0/0
|
|
rules_egress:
|
|
- proto: all
|
|
from_port: all
|
|
to_port: all
|
|
cidr_ip: 0.0.0.0/0
|
|
tags: mining
|
|
|
|
|
|
- name: Create mining
|
|
hosts: localhost
|
|
gather_facts: False
|
|
vars:
|
|
volumes:
|
|
- device_name: /dev/sda1
|
|
volume_size: 128
|
|
delete_on_termination: true
|
|
tasks:
|
|
- name: Launch instance
|
|
ec2:
|
|
ec2_access_key: "{{ access_key }}"
|
|
ec2_secret_key: "{{ secret_key }}"
|
|
key_name: "{{ awskeypair_name }}"
|
|
instance_tags:
|
|
Name: "{{ mining_instance_name }}"
|
|
group: "{{ mining_security_group }}"
|
|
instance_type: "{{ mining_instance_type }}"
|
|
image: "{{ image }}"
|
|
count: "{{ mining_count_instances }}"
|
|
wait: yes
|
|
region: "{{ region }}"
|
|
vpc_subnet_id: "{{ vpc_subnet_id }}"
|
|
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 }}"
|
|
tags: mining
|
|
|
|
- name: Installing python
|
|
hosts: all
|
|
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: Configure instance(s)
|
|
hosts: launched
|
|
user: ubuntu
|
|
become: True
|
|
vars:
|
|
ansible_ssh_port: 22
|
|
gather_facts: True
|
|
roles:
|
|
- preconf
|
|
tags: preconf
|
|
tasks:
|
|
- name: restart machine after setup
|
|
shell: shutdown -r 1
|