From e508dbef1fbcebb59d2e35fb0c5acc65a0186fae Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Mon, 5 Dec 2016 10:34:05 -0800 Subject: [PATCH] assorted small fixes, add some management infrastructure --- group_vars/all | 3 +- inventory/asg-inventory.py | 2 +- roles/aws-infrastructure/tasks/main.yml | 43 +++++++++++++++++++++++++ roles/common/tasks/main.yml | 4 +-- sqs-action.py | 3 +- 5 files changed, 50 insertions(+), 5 deletions(-) diff --git a/group_vars/all b/group_vars/all index 257b7ad..9303d43 100644 --- a/group_vars/all +++ b/group_vars/all @@ -1,3 +1,4 @@ --- -ACCT_ID: 123456789012 +ACCT_ID: "123456789012" VPC_SUBNETS: "subnet-1234abcd,subnet-5678ef01" +DEFAULT_AMI: "ami-b04e92d0" # Amazon Linux AMI 2016.09.0 \ No newline at end of file diff --git a/inventory/asg-inventory.py b/inventory/asg-inventory.py index 74e21b0..1eba92e 100755 --- a/inventory/asg-inventory.py +++ b/inventory/asg-inventory.py @@ -68,7 +68,7 @@ def regionInventory(sessionArgs, publicIPs=False): inventory = {iid:[AllInstanceIPs[iid]] for iid in AllInstanceIPs} # add ASG dict, replacing ASG Instance Id with instance IP - inventory.update({asg:[AllInstanceIPs[iid] for iid in ASGs[asg]] for asg in ASGs}) + inventory.update({asg:[AllInstanceIPs[iid] for iid in ASGs[asg] if iid in AllInstanceIPs] for asg in ASGs}) return inventory diff --git a/roles/aws-infrastructure/tasks/main.yml b/roles/aws-infrastructure/tasks/main.yml index 49bc640..0f1a390 100644 --- a/roles/aws-infrastructure/tasks/main.yml +++ b/roles/aws-infrastructure/tasks/main.yml @@ -98,3 +98,46 @@ interval: 30 unhealthy_threshold: 2 healthy_threshold: 2 + + - name: management iam + iam: + name: management + iam_type: role + state: present + + - name: management lc + ec2_lc: + name: management-0000 + image_id: "{{ DEFAULT_AMI }}" + key_name: management-key + security_groups: + - management + - sshOnly + instance_type: m4.large + volumes: + - device_name: /dev/sda1 + volume_size: 8 + volume_type: gp2 + delete_on_termination: true + - device_name: /dev/sdb + ephemeral: ephemeral0 + - device_name: /dev/sdc + ephemeral: ephemeral1 + - device_name: /dev/sdd + ephemeral: ephemeral2 + - device_name: /dev/sde + ephemeral: ephemeral3 + register: mgmt_lc + + - name: management asg + ec2_asg: + name: management + min_size: 1 + max_size: 1 + desired_capacity: 1 + vpc_zone_identifier: "{{ MANAGEMENT_SUBNET }}" + launch_config_name: "{{ mgmt_lc.something.name }}" + tags: + - module: management + propogate_at_launch: yes + diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml index 02f3b0a..b92b517 100644 --- a/roles/common/tasks/main.yml +++ b/roles/common/tasks/main.yml @@ -5,7 +5,7 @@ when: ASSET_PATH is defined file: state: directory - path: {{ ASSET_PATH }} + path: "{{ ASSET_PATH }}" mode: "0755" owner: root group: root @@ -49,7 +49,7 @@ with_items: "{{ fact_scripts|default(None) }}" copy: dest: /etc/ansible/facts.d/{{ item }}.fact - src: {{ item }}.fact + src: "{{ item }}.fact" mode: "0755" owner: root group: root diff --git a/sqs-action.py b/sqs-action.py index 54f2eb7..f092fd7 100755 --- a/sqs-action.py +++ b/sqs-action.py @@ -62,12 +62,13 @@ def processMessage(message): instanceState = ec2r.Instance(InstanceId).state['Name'] except: logging.debug('instance %s does not exist', InstanceId) - message.delete() + message.change_visibility(VisibilityTimeout=60 * 2) else: if instanceState == 'running': handleEvent(message, event, ASGName, InstanceId) else: logging.debug('instance %s is in state %s, will try again', InstanceId, instanceState) + message.change_visibility(VisibilityTimeout=60 * 2) else: logging.debug('nothing to do for event %r', data) message.delete() -- 2.45.2