Erik M Jacobs
2017-02-14 18c8a129dbd7f3143abd72245085baefca927678
Switches to use an include of a post_software playbook based on env_type

* increases connection timeout
* changes ec2.ini (although will need more changes for prod)
* loads a post_software playbook from the config folder
* adds an empty bu-workshop post_software playbook
1 files added
3 files modified
156 ■■■■■ changed files
ansible.cfg 5 ●●●●● patch | view | raw | blame | history
ansible/configs/bu-workshop/post_software.yml 7 ●●●●● patch | view | raw | blame | history
ansible/inventory/ec2.ini 51 ●●●● patch | view | raw | blame | history
ansible/main.yml 93 ●●●● patch | view | raw | blame | history
ansible.cfg
@@ -1,15 +1,14 @@
[defaults]
forks = 50
host_key_checking = False
#hostfile = ./scripts/ec2.py
become = True
gathering = smart
fact_caching = jsonfile
fact_caching_connection = .ansible_facts
host_key_checking = False
# dealing with escalation prompt errors on slow links
timeout = 60
# override ssh_config ControlPath to use hashed value to handle long node names
[ssh_connection]
#control_path = /tmp/
control_path = /tmp/%%h-%%r
#ssh_args = -F ./ssh.cfg -o ControlMaster=auto -o ControlPersist=30m
ansible/configs/bu-workshop/post_software.yml
New file
@@ -0,0 +1,7 @@
- name: Post software deployment
  hosts: localhost
  connection: local
  become: false
  tasks:
    - debug:
        msg: "Post deployment empty"
ansible/inventory/ec2.ini
@@ -11,9 +11,8 @@
# AWS regions to make calls to. Set this to 'all' to make request to all regions
# in AWS and merge the results together. Alternatively, set this to a comma
# separated list of regions. E.g. 'us-east-1,us-west-1,us-west-2'
regions = ap-southeast-2,us-east-1,eu-central-1
#regions = all
regions_exclude = ap-south-1,us-gov-west-1,cn-north-1
regions = us-east-1
regions_exclude = us-gov-west-1, cn-north-1
# When generating inventory, Ansible needs to know how to address a server.
# Each EC2 instance has a lot of variables associated with it. Here is the list:
@@ -34,7 +33,6 @@
# This allows you to override the inventory_name with an ec2 variable, instead
# of using the destination_variable above. Addressing (aka ansible_ssh_host)
# will still use destination_variable. Tags should be written as 'tag_TAGNAME'.
#hostname_variable = tag_Name
hostname_variable = public_dns_name
# For server inside a VPC, using DNS names may not make sense. When an instance
@@ -60,8 +58,8 @@
# To tag instances on EC2 with the resource records that point to them from
# Route53, uncomment and set 'route53' to True.
#route53 = False
route53 = False
# To exclude RDS instances from the inventory, uncomment and set to False.
#rds = False
@@ -124,43 +122,24 @@
# The EC2 inventory output can become very large. To manage its size,
# configure which groups should be created.
#group_by_instance_id = True
#group_by_region = True
#group_by_availability_zone = True
#group_by_aws_account = False
#group_by_ami_id = True
#group_by_instance_type = True
#group_by_key_pair = True
#group_by_vpc_id = True
#group_by_security_group = True
#group_by_tag_keys = True
#group_by_tag_none = True
#group_by_route53_names = True
#group_by_rds_engine = True
#group_by_rds_parameter_group = True
#group_by_elasticache_engine = True
#group_by_elasticache_cluster = True
#group_by_elasticache_parameter_group = True
#group_by_elasticache_replication_group = True
group_by_instance_id = False
group_by_region = False
group_by_availability_zone = False
group_by_instance_id = True
group_by_region = True
group_by_availability_zone = True
group_by_aws_account = False
group_by_ami_id = False
group_by_instance_type = False
group_by_ami_id = True
group_by_instance_type = True
group_by_key_pair = True
group_by_vpc_id = True
group_by_security_group = True
group_by_tag_keys = True
group_by_tag_none = True
group_by_route53_names = False
group_by_rds_engine = False
group_by_rds_parameter_group = False
group_by_elasticache_engine = False
group_by_elasticache_cluster = False
group_by_elasticache_parameter_group = False
group_by_elasticache_replication_group = False
group_by_route53_names = True
group_by_rds_engine = True
group_by_rds_parameter_group = True
group_by_elasticache_engine = True
group_by_elasticache_cluster = True
group_by_elasticache_parameter_group = True
group_by_elasticache_replication_group = True
# If you only want to include hosts that match a certain regular expression
# pattern_include = staging-*
ansible/main.yml
@@ -1,42 +1,5 @@
#vim: set ft=ansible:
# vim: set ft=ansible:
---
################################################################################
################################################################################
############ Step 000 Pre Infrastructure Deploy Tasks
################################################################################
################################################################################
- name: Step 000 Pre Infrastructure Deploy Tasks
  hosts: localhost
  connection: local
  gather_facts: False
  vars_files:
    - "{{ playbook_dir }}/configs/{{ env_type }}/env_vars.yml"
    - "{{ playbook_dir }}/configs/{{ env_type }}/env_secret_vars.yml"
  tags:
    - step000
    - pre_infra_tasks
  tasks:
    - name: Check for "pre_infra tasks"
      find:
        paths: "{{ playbook_dir }}/configs/{{ env_type }}"
        recurse: yes
        file_type: file
        patterns: ".*pre_infra.*"
        use_regex: true
      failed_when: no
      changed_when: false
      register: pre_infra_tasks
    - include: "{{ item.path }}"
      with_items: "{{ pre_infra_tasks.files }}"
      when: pre_infra_tasks.matched|int != 0
    - debug:
        var: all
    - debug:
        var: bastions
#################################################################################
#################################################################################
############# Step 001 Deploy Infrastructure
@@ -72,6 +35,26 @@
        bastion_hostname: "{{ hostvars[ groups[ ('tag_' ~ env_type ~ '_' ~ guid ~ '_bastion') | replace('-', '_') ].0 ]['ec2_public_dns_name'] }}"
    #TODO: May still want to generate an SSH config for later use
- name: Wait for readiness
  hosts: "{{ ('tag_' ~ env_type ~ '_' ~ guid ~ '_bastion' ) | replace('-', '_') }}"
  vars_files:
    - "{{ playbook_dir }}/configs/{{ env_type }}/env_vars.yml"
    - "{{ playbook_dir }}/configs/{{ env_type }}/env_secret_vars.yml"
    - "{{ playbook_dir }}/configs/{{ env_type }}/ssh_vars.yml"
  gather_facts: False
  any_errors_fatal: true
  tags:
    - common_tasks
    - wait_ssh
  tasks:
    - name: wait for host to be available
      wait_for:
        host: '{{ inventory_hostname }}'
        port: 22
        search_regex: OpenSSH
      with_items:
        - "{{ ('tag_Project_' ~ env_type ~ '_' ~ guid) | replace('-', '_') }}"
#################################################################################
#################################################################################
@@ -172,6 +155,10 @@
    - bastion_tasks
- include: "{{ playbook_dir }}/software_playbooks/{{ software_to_deploy }}.yml"
  tags:
    - step004
    - deploy_software
    - software_to_deploy
################################################################################
################################################################################
@@ -179,35 +166,7 @@
################################################################################
################################################################################
- name: Step 005 Post Software Deploy Tasks
  hosts: localhost
  connection: local
  gather_facts: False
  vars_files:
    - "{{ playbook_dir }}/configs/{{ env_type }}/env_vars.yml"
    - "{{ playbook_dir }}/configs/{{ env_type }}/env_secret_vars.yml"
    - "{{ playbook_dir }}/configs/{{ env_type }}/ssh_vars.yml"
- include: "{{ playbook_dir }}/configs/{{ env_type }}/post_software.yml"
  tags:
    - step005
    - post_software_tasks
  tasks:
    - name: Check for "post_software tasks"
      find:
        paths: "{{playbook_dir}}/configs/{{ env_type }}"
        recurse: yes
        file_type: file
        patterns: ".*post_software.*tasks"
        use_regex: true
      failed_when: no
      changed_when: false
      register: post_software_tasks
    - include: "{{item.path}}"
      with_items: "{{post_software_tasks.files}}"
      when: post_software_tasks.matched|int != 0
# Include tasks (above) and include playbooks (below) don't work the same, by
# including the as a tasks file you cannot use "hosts" and execute plays
# When including as a playbook, you can list lplays and use "hosts"
# current issue is that "playbook" include does not allow using "with_items" and
# cannot be added dynamically - I'm sure this can be fixed