From: Justin Wind Date: Tue, 14 Mar 2017 21:25:11 +0000 (-0700) Subject: use common framework for management infrastructure X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=2be808f1cda5ad35585eb925ee640a96ba908787;p=awsible use common framework for management infrastructure --- diff --git a/init_management.yml b/init_management-dev.yml similarity index 53% rename from init_management.yml rename to init_management-dev.yml index 97302ba..56a41f6 100644 --- a/init_management.yml +++ b/init_management-dev.yml @@ -4,4 +4,6 @@ gather_facts: False become: no roles: - - aws-management-infrastructure + - role: aws-management-infrastructure + phase: dev + version: "0000" diff --git a/management.yml b/management-d0dev.yml similarity index 67% rename from management.yml rename to management-d0dev.yml index a6ce26a..a1e1dc0 100644 --- a/management.yml +++ b/management-d0dev.yml @@ -1,5 +1,5 @@ --- -- hosts: management +- hosts: management-d0dev become: true roles: - common diff --git a/roles/autoscalinggroup/tasks/main.yml b/roles/autoscalinggroup/tasks/main.yml index d0c1692..694f7dc 100644 --- a/roles/autoscalinggroup/tasks/main.yml +++ b/roles/autoscalinggroup/tasks/main.yml @@ -10,11 +10,16 @@ - set_fact: asg_n: - "{{ module }}" - - "{{ stack }}" - - "{{ country|ternary('c0', '') }}{{ country|default('') }}" - - "{{ phase|ternary('d0', '') }}{{ phase|default('') }}" + - "{{ stack|default() }}" + - "{{ (country|default() != '')|ternary('c0', '') }}{{ country|default('') }}" + - "{{ (phase|default() != '')|ternary('d0', '') }}{{ phase|default('') }}" + +- set_fact: + partial_subnet_ids: "{{ subnet_ids }}" + when: subnet_ids is defined - name: suss out our subnets + when: partial_subnet_ids is not defined ec2_vpc_subnet_facts: region: "{{ vpc_region }}" filters: @@ -39,10 +44,10 @@ propagate_at_launch: yes - module: "{{ module }}" propagate_at_launch: yes - - stack: "{{ stack }}" + - stack: "{{ stack|default() }}" propagate_at_launch: yes - - country: "{{ country }}" + - country: "{{ country|default() }}" propagate_at_launch: yes - - phase: "{{ phase }}" + - phase: "{{ phase|default() }}" propagate_at_launch: yes diff --git a/roles/aws-management-infrastructure/defaults/main.yml b/roles/aws-management-infrastructure/defaults/main.yml index 0db972b..d207168 100644 --- a/roles/aws-management-infrastructure/defaults/main.yml +++ b/roles/aws-management-infrastructure/defaults/main.yml @@ -4,3 +4,6 @@ MANAGEMENT_EVENT_QUEUE_SHORT: management MANAGEMENT_EVENT_FAILURE_QUEUE: "{{ MANAGEMENT_EVENT_QUEUE }}-failed" MANAGEMENT_NOTICE_TOPIC: management-notifications MANAGEMENT_NOTICE_TOPIC_SHORT: notices +module: management +zone: priv +instance_type: m4.large diff --git a/roles/aws-management-infrastructure/tasks/main.yml b/roles/aws-management-infrastructure/tasks/main.yml index d0edb77..7db2e1a 100644 --- a/roles/aws-management-infrastructure/tasks/main.yml +++ b/roles/aws-management-infrastructure/tasks/main.yml @@ -3,6 +3,8 @@ that: - MANAGEMENT_SUBNET != '' - DEFAULT_AMI != '' + - version != '' + - phase != '' tags: ['check_vars'] - name: sg management-elb @@ -58,6 +60,7 @@ interval: 30 unhealthy_threshold: 2 healthy_threshold: 2 + register: elb_management - name: management key ec2_key: @@ -81,60 +84,77 @@ # - arn:aws:iam::{{ ACCT_ID }}:policy/base-policy # - arn:aws:iam::{{ ACCT_ID }}:policy/management-policy -# will need to rev name-version when changing AMI -- name: management lc - ec2_lc: - region: "{{ vpc_region }}" - name: management-0000 - image_id: "{{ DEFAULT_AMI }}" - key_name: "{{ MANAGEMENT_KEY_NAME }}" - instance_profile_name: management - security_groups: - - "{{ sg_management.group_id }}" - - "{{ sg_ssh.group_id }}" - instance_type: m4.large - volumes: -# setting the root volume seems to prevent instances from launching -# - 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 +- include_role: + name: launchconfig + vars: + security_group_ids: + - "{{ sg_ssh.group_id }}" + - "{{ sg_icmp.group_id }}" + - "{{ sg_management.group_id }}" -- name: management asg - ec2_asg: - region: "{{ vpc_region }}" - name: management +# # will need to rev name-version when changing AMI +# - name: management lc +# ec2_lc: +# region: "{{ vpc_region }}" +# name: management-0000 +# image_id: "{{ DEFAULT_AMI }}" +# key_name: "{{ MANAGEMENT_KEY_NAME }}" +# instance_profile_name: management +# security_groups: +# - "{{ sg_management.group_id }}" +# - "{{ sg_ssh.group_id }}" +# - "{{ sg_icmp.group_id }}" +# instance_type: m4.large +# volumes: +# # setting the root volume seems to prevent instances from launching +# # - 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 + +- include_role: + name: autoscalinggroup + vars: + load_balancers: "{{ elb_management.elb.name }}" min_size: 1 max_size: 1 - desired_capacity: 1 - default_cooldown: 10 - vpc_zone_identifier: "{{ MANAGEMENT_SUBNET }}" - launch_config_name: "{{ mgmt_lc.name|default('checkmode') }}" - notification_topic: "{{ management_topic.sns_arn }}" - notification_types: - - autoscaling:EC2_INSTANCE_LAUNCH - load_balancers: - - management-int-elb - tags: - - account: "{{ ACCT_NAME }}" - propagate_at_launch: yes - - module: management - propagate_at_launch: yes - - stack: "" - propagate_at_launch: yes - - country: "" - propagate_at_launch: yes - - phase: dev - propagate_at_launch: yes + subnet_ids: "{{ MANAGEMENT_SUBNET }}" + +# - name: management asg +# ec2_asg: +# region: "{{ vpc_region }}" +# name: management +# min_size: 1 +# max_size: 1 +# desired_capacity: 1 +# default_cooldown: 10 +# vpc_zone_identifier: "{{ MANAGEMENT_SUBNET }}" +# launch_config_name: "{{ mgmt_lc.name|default('checkmode') }}" +# notification_topic: "{{ management_topic.sns_arn }}" +# notification_types: +# - autoscaling:EC2_INSTANCE_LAUNCH +# load_balancers: +# - management-int-elb +# tags: +# - account: "{{ ACCT_NAME }}" +# propagate_at_launch: yes +# - module: management +# propagate_at_launch: yes +# - stack: "" +# propagate_at_launch: yes +# - country: "" +# propagate_at_launch: yes +# - phase: dev +# propagate_at_launch: yes - name: not implemented yet debug: diff --git a/roles/launchconfig/tasks/main.yml b/roles/launchconfig/tasks/main.yml index 59768fd..ced0bcd 100644 --- a/roles/launchconfig/tasks/main.yml +++ b/roles/launchconfig/tasks/main.yml @@ -12,22 +12,22 @@ - set_fact: ud_cluster: - "{{ module }}" - - "{{ country|ternary('c0', '') }}{{ country|default('') }}" - - "{{ phase|ternary('d0', '') }}{{ phase|default('') }}" + - "{{ (country|default() != '')|ternary('c0', '') }}{{ country|default('') }}" + - "{{ (phase|default() != '')|ternary('d0', '') }}{{ phase|default('') }}" - set_fact: ud_asgn: - "{{ module }}" - "{{ stack|default('') }}" - - "{{ country|ternary('c0', '') }}{{ country|default('') }}" - - "{{ phase|ternary('d0', '') }}{{ phase|default('') }}" + - "{{ (country|default() != '')|ternary('c0', '') }}{{ country|default('') }}" + - "{{ (phase|default() != '')|ternary('d0', '') }}{{ phase|default('') }}" - set_fact: lc_n: - "{{ module }}" - "{{ stack|default('') }}" - - "{{ country|ternary('c0', '') }}{{ country|default('') }}" - - "{{ phase|ternary('d0', '') }}{{ phase|default('') }}" + - "{{ (country|default() != '')|ternary('c0', '') }}{{ country|default('') }}" + - "{{ (phase|default() != '')|ternary('d0', '') }}{{ phase|default('') }}" - "{{ version }}" - name: assemble user data