From aa6d30655047be1b0df8eb3177d6a4507ce2f388 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=B6rg=20Sachse?= <Joerg.Sachse@slub-dresden.de>
Date: Tue, 10 Nov 2020 11:55:46 +0100
Subject: [PATCH] refactor: move ISO creation to separate role

---
 site.yml                   | 129 ++++++++-----------------------------
 templates/isolinux.cfg.j2  | 117 ---------------------------------
 templates/kickstart.cfg.j2 |  53 ---------------
 vars/network.yml.example   |   6 --
 4 files changed, 28 insertions(+), 277 deletions(-)
 delete mode 100644 templates/isolinux.cfg.j2
 delete mode 100644 templates/kickstart.cfg.j2
 delete mode 100644 vars/network.yml.example

diff --git a/site.yml b/site.yml
index 1398068..e38357e 100644
--- a/site.yml
+++ b/site.yml
@@ -1,103 +1,30 @@
 ---
-- hosts: localhost
-  connection: local
-  vars:
-    - ISO: "RHEL79"
-  vars_prompt:
-    - name: install_hostname
-      prompt: "What's the hostname of the system that you're trying to install? Use ONLY the hostname, NOT the FQDN!"
-      private: false
-  tasks:
-    ### PREPARATION
-    - name: create build directory
-      file:
-        path: "{{ playbook_dir }}/build/"
-        state: directory
-    - name: mount boot ISO
-      mount:
-        fstype: "iso9660"
-        opts: "loop"
-        path: "{{ playbook_dir }}/iso/"
-        src: "{{ playbook_dir }}/rhel-server-7.9-x86_64-dvd.iso"
-        fstab: "/tmp/fstab"
-        state: mounted
-    - name: copy ISO contents
-      shell:
-        cmd: 'cp -avRf "{{ playbook_dir }}/iso" "{{ playbook_dir }}/build"'
-      ignore_errors: true
-    - name: check if listfile for networking exists...
-      find:
-        paths: "{{ playbook_dir }}/vars/"
-        patterns: "network.yml"
-      register: result_network
-    - name: ... and bail out if config file doesn't exist
-      fail:
-        msg: "The required config file 'vars/network.yml' couldn't be found. Please refer to vars/network.yml.example for further documentation."
-      when: "result_network.matched < 1"
-    - name: include networking variables
-      include_vars: "{{ item.path }}"
-      loop: "{{ result_network.files }}"
+- hosts: "*"
+  pre_tasks:
+    - name: Verify that the installed version of Ansible meets this playbook's version requirements.
+      assert:
+        that: "ansible_version.full is version_compare('2.5', '>=')"
+        msg: >
+          "You must update Ansible to at least 2.5 to use this playbook."
+  # Collect facts from remote system? Possible values: true, false
+  gather_facts: true
+  # Gather only certain subsects of facts. Ansible supports network, hardware, virtual, facter, ohai as subset.
+  gather_subset:
+    - network
+    - virtual
+    - hardware
+  # any_error_fatal will mark all the hosts as failed if fails and immediately abort the playbook execution. Possible values: true, false
+  any_errors_fatal: false
+  # max_fail_percentage allows you to abort the play if certain threshold of failures have been reached.
+  max_fail_percentage: 30
+  serial: 30
+  # hide sensitive information in verbose/debugging output from others. Possible values: true, false
+  no_log: false
+  # execution strategy, possible values: debug, linear, serial, free (https://docs.ansible.com/ansible/latest/user_guide/playbooks_strategies.html)
+  strategy: linear
 
-    ### CREATE CONFIGS
-    - name: write Kickstart files
-      template:
-        src: "kickstart.cfg.j2"
-        dest: "build/{{ item.hostname }}.cfg"
-      loop: "{{ hosts }}"
-    - name: template isolinux config
-      template:
-        src: "isolinux.cfg.j2"
-        dest: "{{ playbook_dir }}/build/isolinux/isolinux.cfg"
-      loop: "{{ hosts }}"
-      when: "install_hostname in item.hostname"
-
-    ### CREATE ISO INSTALLATION IMAGE
-    - name: create ISO image
-      command:
-        cmd: 'xorrisofs -output {{ playbook_dir }}/build/{{ ISO }}.iso -eltorito-boot isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -volid "{{ ISO }}" -rational-rock {{ playbook_dir }}/build/'
-        chdir: "{{ playbook_dir }}/build"
-    - name: make ISO bootable
-      command: 'isohybrid -v {{ playbook_dir }}/build/{{ ISO }}.iso'
-
-    ### CLEANUP
-    - name: umount boot ISO
-      mount:
-        path: "{{ playbook_dir }}/iso"
-        state: unmounted
-    - name: clean up
-      file:
-        path: "{{ item }}"
-        state: absent
-      loop:
-        - "/tmp/fstab"
-        - "{{ playbook_dir }}/iso/"
-
-#- hosts: "*"
-#  pre_tasks:
-#    - name: Verify that the installed version of Ansible meets this playbook's version requirements.
-#      assert:
-#        that: "ansible_version.full is version_compare('2.5', '>=')"
-#        msg: >
-#          "You must update Ansible to at least 2.5 to use this playbook."
-#  # Collect facts from remote system? Possible values: true, false
-#  gather_facts: true
-#  # Gather only certain subsects of facts. Ansible supports network, hardware, virtual, facter, ohai as subset.
-#  gather_subset:
-#    - network
-#    - virtual
-#    - hardware
-#  # any_error_fatal will mark all the hosts as failed if fails and immediately abort the playbook execution. Possible values: true, false
-#  any_errors_fatal: false
-#  # max_fail_percentage allows you to abort the play if certain threshold of failures have been reached.
-#  max_fail_percentage: 30
-#  serial: 30
-#  # hide sensitive information in verbose/debugging output from others. Possible values: true, false
-#  no_log: false
-#  # execution strategy, possible values: debug, linear, serial, free (https://docs.ansible.com/ansible/latest/user_guide/playbooks_strategies.html)
-#  strategy: linear
-#
-#  roles:
-#    - { role: ansible_lza_bootstrap_rhel_server }
-#    # - { role: ansible_lza_install_common, become: true }
-#    # - { role: ansible_lza_server_hardening, become: true }
-#    # - { role: ansible_lza_rosetta_app, become: true }
+  roles:
+    - { role: ansible_lza_bootstrap_rhel_server }
+    # - { role: ansible_lza_install_common, become: true }
+    # - { role: ansible_lza_server_hardening, become: true }
+    # - { role: ansible_lza_rosetta_app, become: true }
diff --git a/templates/isolinux.cfg.j2 b/templates/isolinux.cfg.j2
deleted file mode 100644
index fdbd290..0000000
--- a/templates/isolinux.cfg.j2
+++ /dev/null
@@ -1,117 +0,0 @@
-default vesamenu.c32
-timeout 600
-
-display boot.msg
-
-# Clear the screen when exiting the menu, instead of leaving the menu displayed.
-# For vesamenu, this means the graphical background is still displayed without
-# the menu itself for as long as the screen remains in graphics mode.
-menu clear
-menu background splash.png
-menu title Red Hat Enterprise Linux 7.9
-menu vshift 8
-menu rows 18
-menu margin 8
-#menu hidden
-menu helpmsgrow 15
-menu tabmsgrow 13
-
-# Border Area
-menu color border * #00000000 #00000000 none
-
-# Selected item
-menu color sel 0 #ffffffff #00000000 none
-
-# Title bar
-menu color title 0 #ff7ba3d0 #00000000 none
-
-# Press [Tab] message
-menu color tabmsg 0 #ff3a6496 #00000000 none
-
-# Unselected menu item
-menu color unsel 0 #84b8ffff #00000000 none
-
-# Selected hotkey
-menu color hotsel 0 #84b8ffff #00000000 none
-
-# Unselected hotkey
-menu color hotkey 0 #ffffffff #00000000 none
-
-# Help text
-menu color help 0 #ffffffff #00000000 none
-
-# A scrollbar of some type? Not sure.
-menu color scrollbar 0 #ffffffff #ff355594 none
-
-# Timeout msg
-menu color timeout 0 #ffffffff #00000000 none
-menu color timeout_msg 0 #ffffffff #00000000 none
-
-# Command prompt text
-menu color cmdmark 0 #84b8ffff #00000000 none
-menu color cmdline 0 #ffffffff #00000000 none
-
-# Do not display the actual menu unless the user presses a key. All that is displayed is a timeout message.
-
-menu tabmsg Press Tab for full configuration options on menu items.
-
-menu separator # insert an empty line
-menu separator # insert an empty line
-
-##### Begin INSERTED FOR ANSIBLE ROLE #####
-label netinstall
-  menu label Install Red Hat Enterprise Linux 7.9 ^Netinstall Server
-  menu default
-  kernel vmlinuz
-  append initrd=initrd.img inst.ks=cdrom:/{{ item.hostname }}.cfg inst.stage2=hd:LABEL=RHEL79 quiet
-#####  End  INSERTED FOR ANSIBLE ROLE #####
-
-menu separator # insert an empty line
-
-# utilities submenu
-menu begin ^Troubleshooting
-  menu title Troubleshooting
-
-label vesa
-  menu indent count 5
-  menu label Install Red Hat Enterprise Linux 7.9 in ^basic graphics mode
-  text help
-	Try this option out if you're having trouble installing
-	Red Hat Enterprise Linux 7.9.
-  endtext
-  kernel vmlinuz
-  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.9\x20Server.x86_64 xdriver=vesa nomodeset quiet
-
-label rescue
-  menu indent count 5
-  menu label ^Rescue a Red Hat Enterprise Linux system
-  text help
-	If the system will not boot, this lets you access files
-	and edit config files to try to get it booting again.
-  endtext
-  kernel vmlinuz
-  append initrd=initrd.img inst.stage2=hd:LABEL=RHEL-7.9\x20Server.x86_64 rescue quiet
-
-label memtest
-  menu label Run a ^memory test
-  text help
-	If your system is having issues, a problem with your
-	system's memory may be the cause. Use this utility to
-	see if the memory is working correctly.
-  endtext
-  kernel memtest
-
-menu separator # insert an empty line
-
-label local
-  menu label Boot from ^local drive
-  localboot 0xffff
-
-menu separator # insert an empty line
-menu separator # insert an empty line
-
-label returntomain
-  menu label Return to ^main menu
-  menu exit
-
-menu end
diff --git a/templates/kickstart.cfg.j2 b/templates/kickstart.cfg.j2
deleted file mode 100644
index c73c7b6..0000000
--- a/templates/kickstart.cfg.j2
+++ /dev/null
@@ -1,53 +0,0 @@
-#version=DEVEL
-# System authorization information
-auth --enableshadow --passalgo=sha512
-# Use CDROM installation media
-cdrom
-# Use graphical install
-graphical
-# Run the Setup Agent on first boot
-firstboot --enable
-ignoredisk --only-use=sda
-# Keyboard layouts
-keyboard --vckeymap=de-nodeadkeys --xlayouts='de (nodeadkeys)'
-# System language
-lang de_DE.UTF-8
-
-# Network information
-network  --bootproto=static --device=ens192 --ethtool="autoneg on" --gateway=212.201.61.1 --ip={{ item.ip_address }} --nameserver=194.95.142.157,194.95.142.203,194.95.142.200 --netmask=255.255.255.192 --ipv6=auto --activate
-network  --hostname={{ item.hostname }}.slub-dresden.de
-
-repo --name="Server-HighAvailability" --baseurl=file:///run/install/repo/addons/HighAvailability
-repo --name="Server-ResilientStorage" --baseurl=file:///run/install/repo/addons/ResilientStorage
-# Root password
-rootpw --iscrypted $6$67rCX4MFo0HPCG0T$7DsUx/fFJ067LS5QDtRMDTIcMrq1FejZOp/Ei4o.L08cbYC2FVsJ4Tp45iKrZDfL0df7qgeWpY7ylBfI3k/7b1
-# System services
-services --enabled="chronyd"
-# System timezone
-timezone Europe/Berlin --isUtc
-# System bootloader configuration
-bootloader --append=" crashkernel=auto" --location=mbr --boot-drive=sda
-# Partition clearing information
-clearpart --none --initlabel
-# Disk partitioning information
-part / --fstype="ext4" --ondisk=sda --size=143360
-part swap --fstype="swap" --ondisk=sda --size=5120
-part /boot --fstype="xfs" --ondisk=sda --size=1024
-
-%packages
-@^minimal
-@core
-chrony
-kexec-tools
-
-%end
-
-%addon com_redhat_kdump --enable --reserve-mb='auto'
-
-%end
-
-%anaconda
-pwpolicy root --minlen=6 --minquality=1 --notstrict --nochanges --notempty
-pwpolicy user --minlen=6 --minquality=1 --notstrict --nochanges --emptyok
-pwpolicy luks --minlen=6 --minquality=1 --notstrict --nochanges --notempty
-%end
diff --git a/vars/network.yml.example b/vars/network.yml.example
deleted file mode 100644
index c363aa5..0000000
--- a/vars/network.yml.example
+++ /dev/null
@@ -1,6 +0,0 @@
----
-- hostname: localhost
-  ip_address: 127.0.0.1
-- hostname: example_host
-  ip_address: 123.234.213.132
-# add/edit more hosts as necessary
-- 
GitLab