From bc2ced27c2a30f4fe14ffb02b7dafd4fd78aff38 Mon Sep 17 00:00:00 2001 From: Jesse Pretorius Date: Tue, 26 Jun 2018 10:11:34 +0100 Subject: [PATCH] MNAIO: Ensure a consistent and readable style This patch implements the following style changes: 1. The 'environment' argument is placed in the same location for all plays, making sure it's easier to find. 2. The play tags are located in the same place, also making sure they're easier to find. 3. The line breaks between tasks and plays are set to be consistently 1 between tasks and 2 between plays. 4. Given that there are no roles being used, the use of pre/post tasks is converted to only using tasks. Change-Id: I2e22c8360d65256b8e44ca1e310e0668a651196d --- multi-node-aio/playbooks/deploy-acng.yml | 12 ++-- multi-node-aio/playbooks/deploy-dhcp.yml | 11 ++-- multi-node-aio/playbooks/deploy-osa.yml | 11 ++-- multi-node-aio/playbooks/deploy-pxe.yml | 11 ++-- multi-node-aio/playbooks/deploy-vms.yml | 70 ++++++++++-------------- multi-node-aio/playbooks/setup-host.yml | 11 ++-- 6 files changed, 49 insertions(+), 77 deletions(-) diff --git a/multi-node-aio/playbooks/deploy-acng.yml b/multi-node-aio/playbooks/deploy-acng.yml index 869b8b79..1cec7d60 100644 --- a/multi-node-aio/playbooks/deploy-acng.yml +++ b/multi-node-aio/playbooks/deploy-acng.yml @@ -15,7 +15,10 @@ - name: Gather facts hosts: pxe_hosts - pre_tasks: + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - deploy-acng + tasks: - name: Gather variables for each operating system include_vars: "{{ item }}" with_first_found: @@ -27,7 +30,6 @@ tags: - always - tasks: - name: Install repo caching server packages package: name: "{{ mnaio_pkg_cache_server_distro_packages }}" @@ -87,7 +89,6 @@ notify: - reload acng - post_tasks: - name: Drop apt package manager proxy copy: content: 'Acquire::http { Proxy "{{ default_ubuntu_mirror_proxy }}"; };' @@ -97,14 +98,9 @@ apt: update_cache: yes - environment: "{{ deployment_environment_variables | default({}) }}" - handlers: - name: reload acng service: name: "apt-cacher-ng" state: restarted enabled: yes - - tags: - - deploy-acng diff --git a/multi-node-aio/playbooks/deploy-dhcp.yml b/multi-node-aio/playbooks/deploy-dhcp.yml index 3eec71de..a77b6ec5 100644 --- a/multi-node-aio/playbooks/deploy-dhcp.yml +++ b/multi-node-aio/playbooks/deploy-dhcp.yml @@ -14,7 +14,10 @@ - name: Gather facts hosts: dhcp_hosts gather_facts: "{{ gather_facts | default(true) }}" - pre_tasks: + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - deploy-dhcpd + tasks: - name: Gather variables for each operating system include_vars: "{{ item }}" with_first_found: @@ -43,7 +46,6 @@ enabled: yes with_items: "{{ mnaio_dhcp_distro_packages }}" - tasks: - name: Create a template in /etc/dhcp/dhcpd.conf template: src: dhcp/dhcpd.conf.j2 @@ -62,14 +64,9 @@ group: root notify: restart dhcpd - environment: "{{ deployment_environment_variables | default({}) }}" - handlers: - name: restart dhcpd service: name: "{{ item }}" state: restarted with_items: "{{ mnaio_dhcp_distro_packages }}" - - tags: - - deploy-dhcpd diff --git a/multi-node-aio/playbooks/deploy-osa.yml b/multi-node-aio/playbooks/deploy-osa.yml index 52f62bf2..5e8f54ee 100644 --- a/multi-node-aio/playbooks/deploy-osa.yml +++ b/multi-node-aio/playbooks/deploy-osa.yml @@ -16,7 +16,10 @@ - name: Setup deploy host hosts: deploy_hosts gather_facts: "{{ gather_facts | default(true) }}" - pre_tasks: + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - deploy-osa + tasks: - name: Gather variables for each operating system include_vars: "{{ item }}" with_first_found: @@ -28,7 +31,6 @@ tags: - always - tasks: # Example read-write git checkout from github - name: Get OSA git: @@ -154,8 +156,3 @@ to the {{ groups['deploy_hosts'][0] }} VM and attach to the "build-osa" tmux session. when: - run_osa | default(true) | bool - - environment: "{{ deployment_environment_variables | default({}) }}" - - tags: - - deploy-osa diff --git a/multi-node-aio/playbooks/deploy-pxe.yml b/multi-node-aio/playbooks/deploy-pxe.yml index 22531b50..3f1f44bd 100644 --- a/multi-node-aio/playbooks/deploy-pxe.yml +++ b/multi-node-aio/playbooks/deploy-pxe.yml @@ -16,7 +16,10 @@ - name: Gather facts hosts: pxe_hosts gather_facts: "{{ gather_facts | default(true) }}" - pre_tasks: + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - deploy-pxe + tasks: - name: Gather variables for each operating system include_vars: "{{ item }}" with_first_found: @@ -69,7 +72,6 @@ when: - tftp_ssh_key is undefined - tasks: - name: Drop NGINX config copy: src: "pxe/sites-enabled.default" @@ -211,8 +213,6 @@ - "/var/lib/tftpboot" - "/var/www/pxe" - environment: "{{ deployment_environment_variables | default({}) }}" - handlers: - name: restart nginx service: @@ -231,6 +231,3 @@ name: "inetutils-inetd" state: restarted enabled: yes - - tags: - - deploy-pxe diff --git a/multi-node-aio/playbooks/deploy-vms.yml b/multi-node-aio/playbooks/deploy-vms.yml index 318e67d4..77ec3437 100644 --- a/multi-node-aio/playbooks/deploy-vms.yml +++ b/multi-node-aio/playbooks/deploy-vms.yml @@ -16,7 +16,10 @@ - name: Gather facts hosts: vm_hosts gather_facts: "{{ gather_facts | default(true) }}" - pre_tasks: + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - deploy-vms + tasks: - name: Gather variables for each operating system include_vars: "{{ item }}" with_first_found: @@ -28,7 +31,6 @@ tags: - always - tasks: - name: Stop running VMs command: "virsh destroy {{ hostvars[item]['server_hostname'] }}" failed_when: false @@ -123,15 +125,13 @@ - hostvars[item]['server_vm'] | default(false) | bool with_items: "{{ groups['pxe_servers'] }}" - environment: "{{ deployment_environment_variables | default({}) }}" - - tags: - - deploy-vms - - name: Create vm_servers group hosts: localhost gather_facts: false + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - deploy-vms tasks: - name: VM Servers group add_host: @@ -141,17 +141,12 @@ - hostvars[item]['server_vm'] | default(false) | bool with_items: "{{ groups['pxe_servers'] }}" - environment: "{{ deployment_environment_variables | default({}) }}" - - tags: - - deploy-vms - - name: Wait for deploy host hosts: vm_servers gather_facts: false any_errors_fatal: true - pre_tasks: + tasks: - name: Wait for connectivity 1 local_action: module: wait_for @@ -162,7 +157,7 @@ timeout: 1500 state: started search_regex: OpenSSH - tasks: + - name: copy host keys copy: src: "{{ item.src }}" @@ -174,12 +169,16 @@ - src: "{{ lookup('env', 'HOME') }}/.ssh/id_rsa.pub" dest: /root/.ssh/id_rsa.pub + # In vm-post-install-script.sh.j2 we chattr +i the interfaces file to prevent # the preseed system from overwriting the file after we've modified it. The # task below simply removes the immutable attribute. - name: Remove immutable attr from /etc/network/interfaces hosts: vm_servers gather_facts: true + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - deploy-vms tasks: - file: path: /etc/network/interfaces @@ -188,16 +187,14 @@ - ansible_distribution | lower == "ubuntu" - ansible_distribution_release | lower == "trusty" - environment: "{{ deployment_environment_variables | default({}) }}" - - tags: - - deploy-vms - - name: Set MaxSessions and MaxStartups to reduce connection failures hosts: vm_servers gather_facts: "{{ gather_facts | default(true) }}" - pre_tasks: + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - deploy-vms + tasks: - name: Gather variables for each operating system include_vars: "{{ item }}" with_first_found: @@ -208,7 +205,7 @@ - "{{ playbook_dir }}/vars/{{ ansible_os_family | lower }}.yml" tags: - always - tasks: + - lineinfile: path: /etc/ssh/sshd_config line: MaxStartups 100 @@ -216,6 +213,7 @@ regexp: '^MaxStartups.*$' notify: - restart sshd + - lineinfile: path: /etc/ssh/sshd_config line: MaxSessions 100 @@ -223,21 +221,20 @@ regexp: '^MaxSessions.*$' notify: - restart sshd + handlers: - name: restart sshd service: name: "{{ ssh_service_name }}" state: restarted - environment: "{{ deployment_environment_variables | default({}) }}" - - tags: - - deploy-vms - - name: Setup cinder host volume hosts: cinder_hosts:swift_hosts gather_facts: false + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - deploy-vms tasks: - name: un-mount deleteme mount mount: @@ -256,15 +253,13 @@ force: true state: absent - environment: "{{ deployment_environment_variables | default({}) }}" - - tags: - - deploy-vms - - name: Setup cinder host volume hosts: cinder_hosts gather_facts: false + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - deploy-vms tasks: - name: Create cinder-volumes lv lvol: @@ -278,15 +273,13 @@ vg: cinder-volumes pvs: "/dev/vmvg00/cinder-volumes00" - environment: "{{ deployment_environment_variables | default({}) }}" - - tags: - - deploy-vms - - name: Setup swift host volume hosts: swift_hosts gather_facts: false + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - deploy-vms tasks: - name: Remove deleteme lv lvol: @@ -329,8 +322,3 @@ - disk1 - disk2 - disk3 - - environment: "{{ deployment_environment_variables | default({}) }}" - - tags: - - deploy-vms diff --git a/multi-node-aio/playbooks/setup-host.yml b/multi-node-aio/playbooks/setup-host.yml index dbf10b90..eaa501ad 100644 --- a/multi-node-aio/playbooks/setup-host.yml +++ b/multi-node-aio/playbooks/setup-host.yml @@ -16,7 +16,10 @@ - name: Gather facts hosts: mnaio_hosts gather_facts: "{{ gather_facts | default(true) }}" - pre_tasks: + environment: "{{ deployment_environment_variables | default({}) }}" + tags: + - setup-host + tasks: - name: Gather variables for each operating system include_vars: "{{ item }}" with_first_found: @@ -78,7 +81,6 @@ retries: 3 delay: 15 - tasks: - name: Ensure root has a .ssh directory file: path: /root/.ssh @@ -281,8 +283,3 @@ echo ${module} | tee -a /etc/modules fi done - - environment: "{{ deployment_environment_variables | default({}) }}" - - tags: - - setup-host