Jesse Pretorius bc2ced27c2 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
2018-06-26 11:54:16 +01:00

234 lines
7.0 KiB
YAML

---
# Copyright 2017, Rackspace US, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in witing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Gather facts
hosts: pxe_hosts
gather_facts: "{{ gather_facts | default(true) }}"
environment: "{{ deployment_environment_variables | default({}) }}"
tags:
- deploy-pxe
tasks:
- name: Gather variables for each operating system
include_vars: "{{ item }}"
with_first_found:
- "{{ playbook_dir }}/vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
- "{{ playbook_dir }}/vars/{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ playbook_dir }}/vars/{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ playbook_dir }}/vars/{{ ansible_distribution | lower }}.yml"
- "{{ playbook_dir }}/vars/{{ ansible_os_family | lower }}.yml"
tags:
- always
- name: Install host distro packages
package:
name: "{{ mnaio_pxe_distro_packages }}"
state: "latest"
update_cache: yes
cache_valid_time: 600
register: _install_host_packages
until: _install_host_packages | success
retries: 3
delay: 15
- name: Create base directories
file:
path: "{{ item }}"
state: directory
owner: "root"
group: "root"
mode: "0755"
with_items:
- /var/www/pxe
- /var/www/pxe/configs
- /var/www/pxe/images
- /var/www/pxe/networking
- /var/www/pxe/scripts
- /var/www/pxe/templates
- /var/lib/tftpboot
- /var/lib/tftpboot/ipxe
- name: Get root public key
command: cat /root/.ssh/id_rsa.pub
register: public_key_get
changed_when: false
when:
- tftp_ssh_key is undefined
- name: Set key facts
set_fact:
tftp_ssh_key: "{{ public_key_get.stdout }}"
when:
- tftp_ssh_key is undefined
- name: Drop NGINX config
copy:
src: "pxe/sites-enabled.default"
dest: /etc/nginx/sites-enabled/default
mode: "0644"
owner: root
group: root
notify:
- restart nginx
- name: Drop tftp-hpa configs
template:
src: "pxe/tftp/tftp-hpa"
dest: /etc/default/tftpd-hpa
mode: "0644"
owner: root
group: root
notify:
- restart tftp-hpa
- name: Download iPXE
get_url:
url: "{{ ipxe_kernel_url }}"
dest: "/var/lib/tftpboot/ipxe.lkrn"
tmp_dest: /tmp/
- name: Drop ipxe default menu
template:
src: "pxe/tftp/boot.ipxe.j2"
dest: "/var/lib/tftpboot/boot.ipxe"
mode: "0644"
owner: root
group: root
- name: network scripts for pxe
template:
src: "pxe/configs/{{ ansible_os_family | lower }}/{{ item.src }}"
dest: /var/www/pxe/{{ item.dir }}/{{ item.dest }}
mode: "0644"
owner: root
group: root
with_items:
- src: basic-interface.cfg
dest: "basic-{{ ansible_os_family | lower }}-interface.cfg"
dir: networking
- src: vm-post-install-script.sh.j2
dest: "vm-post-install-{{ ansible_os_family | lower }}-script.sh"
dir: scripts
- src: general-post-install-script.sh.j2
dest: "general-post-install-{{ ansible_os_family | lower }}-script.sh"
dir: scripts
- name: network scripts for an MNAIO
template:
src: "pxe/configs/{{ ansible_os_family | lower }}/{{ item.src }}"
dest: /var/www/pxe/{{ item.dir }}/{{ item.dest }}
mode: "0644"
owner: root
group: root
when:
- groups['mnaio_hosts'] | default([]) | length > 0
with_items:
- src: mnaio-bridges.cfg.j2
dest: mnaio-bridges.cfg
dir: networking
- src: mnaio-post-install-script.sh.j2
dest: mnaio-post-install-{{ ansible_os_family | lower }}-script.sh
dir: scripts
- name: network scripts for servers
template:
src: "pxe/configs/{{ ansible_os_family | lower }}/vm-bridges.cfg.j2"
dest: /var/www/pxe/networking/{{ hostvars[item]['server_hostname'] }}-bridges.cfg
mode: "0644"
owner: root
group: root
with_items: "{{ groups['pxe_servers'] }}"
- name: tftp configs for servers
template:
src: "pxe/tftp/boot.ipxe.macaddr.j2"
dest: "/var/lib/tftpboot/ipxe/{{ hostvars[item]['server_mac_address'] | replace(':', '-') | lower }}"
mode: "0644"
owner: root
group: root
with_items: "{{ groups['pxe_servers'] }}"
- name: Preseeds for pxe mnaio
template:
src: "pxe/configs/{{ ansible_os_family | lower }}/mnaio.config.j2"
dest: /var/www/pxe/configs/mnaio.config
mode: "0644"
owner: root
group: root
with_dict: "{{ images }}"
- name: Preseeds for pxe vm
template:
src: "pxe/configs/{{ ansible_os_family | lower }}/vm.config.j2"
dest: /var/www/pxe/configs/vm.config
mode: "0644"
owner: root
group: root
with_dict: "{{ images }}"
- name: Preseeds for pxe vm-compute
template:
src: "pxe/configs/{{ ansible_os_family | lower }}/vm-compute.config.j2"
dest: /var/www/pxe/configs/vm-compute.config
mode: "0644"
owner: root
group: root
with_dict: "{{ images }}"
- name: Preseeds for pxe compute
template:
src: "pxe/configs/{{ ansible_os_family | lower }}/compute.config.j2"
dest: /var/www/pxe/configs/compute.config
mode: "0644"
owner: root
group: root
with_dict: "{{ images }}"
- name: Preseeds for pxe infra
template:
src: "pxe/configs/{{ ansible_os_family | lower }}/infra.config.j2"
dest: /var/www/pxe/configs/infra.config
mode: "0644"
owner: root
group: root
with_dict: "{{ images }}"
- name: Ensure permissions are correct
file:
dest: "{{ item }}"
mode: u=rwX,g=rX,o=rX
recurse: yes
with_items:
- "/var/lib/tftpboot"
- "/var/www/pxe"
handlers:
- name: restart nginx
service:
name: "nginx"
state: restarted
enabled: yes
- name: restart tftp-hpa
service:
name: "tftpd-hpa"
state: restarted
enabled: yes
- name: restart inetd
service:
name: "inetutils-inetd"
state: restarted
enabled: yes