Files
toallab-automation/satellite.yml
2020-12-08 23:05:58 -05:00

230 lines
5.7 KiB
YAML

# Playbook to install Satellite server on RHV
- name: Prepare RHV for Build
hosts: localhost
gather_facts: no
tasks:
- name: Obtain SSO token from username / password credentials
redhat.rhv.ovirt_auth:
url: "{{ ovirt_url }}"
username: "{{ ovirt_username }}"
password: "{{ ovirt_password }}"
- name: ISO is uploaded to RHV
redhat.rhv.ovirt_disk:
name: "{{ rhel_iso_filename }}"
upload_image_path: "{{ rhel_iso_path }}/{{ rhel_iso_filename }}"
storage_domain: ssdvdo0
size: 5 GiB
wait: true
bootable: true
format: raw
content_type: iso
register: iso_disk
- name: Create VMs
hosts: "{{ vm_name }}"
connection: local
gather_facts: no
# Never run this, unless specifically enabled
vars:
# Hack to work around virtualenv python interpreter
ansible_python_interpreter: "{{ ansible_playbook_python }}"
tasks:
- name: Remove known_hosts entry
known_hosts:
name: "{{ vm_name }}"
state: absent
- name: Create VM disk
ovirt_disk:
name: "{{ vm_name }}_Disk0"
description: '{{ vm_name }} Primary Disk'
interface: 'virtio_scsi'
size: '{{ disk }}GiB'
state: attached
sparse: yes
wait: true
storage_domain: "ssdvdo0"
async: 300
poll: 15
- name: Create Satellite VM in RHV
ovirt_vm:
name: "{{ vm_name }}"
state: present
memory: "{{ memory}}GiB"
disks:
- name: "{{ vm_name }}_Disk0"
activate: yes
bootable: yes
cpu_cores: "{{ vcpus }}"
cluster: "{{ cluster }}"
operating_system: "rhel_7x64"
type: server
graphical_console:
protocol:
- vnc
boot_devices:
- hd
async: 300
poll: 15
register: vm_result
- name: Assign NIC
ovirt_nic:
interface: virtio
name: nic1
profile: ovirtmgmt
network: ovirtmgmt
state: plugged
vm: "{{ vm_name }}"
register: nic_result
- name: Prepare First Boot Resources
hosts: "{{ vm_name }}"
connection: local
gather_facts: no
tasks:
- name: Create directory for initial boot files
tempfile:
state: directory
register: kstmpdir
- name: Extract ISO files
community.general.iso_extract:
image: "{{ rhel_iso_path }}/{{ rhel_iso_filename }}"
dest: "{{ kstmpdir.path }}"
files:
- isolinux/vmlinuz
- isolinux/initrd.img
# TODO Move out vars
- name: Copy Files to Webserver
hosts: webserver.mgmt.toal.ca
become: yes
tasks:
- name: Generate Kickstart File
template:
src: templates/ks.cfg
dest: "/var/www/ks/{{ vm_name }}.cfg"
- name: Prepare Hypervisor
hosts: "{{ vm_host }}"
tasks:
- name: Temporary Directory
file:
path: "/tmp/{{ vm_name }}"
state: directory
mode: 0755
- name: Transfer files to Hypervisor
copy:
src: "{{ hostvars[vm_name].kstmpdir.path }}/{{ item }}"
dest: "/tmp/{{ vm_name }}/{{ item }}"
loop:
- vmlinuz
- initrd.img
# NOTE: This is not idempotent
- name: First Boot
hosts: localhost
gather_facts: no
vars:
# Hack to work around virtualenv python interpreter
ansible_python_interpreter: "{{ ansible_playbook_python }}"
tasks:
- block:
- name: Start VM with first-boot parameters
ovirt_vm:
name: "{{ vm_name }}"
host: "{{ vm_host }}"
kernel_params_persist: false
cd_iso: "{{ iso_disk.id }}"
kernel_path: "/tmp/{{ vm_name }}/vmlinuz"
kernel_params: "ks=http://192.168.1.199/ks/{{ vm_name }}.cfg inst.stage2=hd:LABEL=RHEL-7.9\\x20Server.x86_64"
initrd_path: "/tmp/{{ vm_name }}/initrd.img"
state: running
- name: Wait for system to shut down after installation
ovirt_vm_info:
pattern: "name={{ vm_name }}"
register: vm_info
until: vm_info['ovirt_vms'][0]['status'] == "down"
delay: 20
retries: 60
when: hostvars[vm_name].vm_result.vm.status != 'up'
- name: Power up VM
ovirt_vm:
name: "{{ vm_name }}"
state: running
- name: VM is running
connection: local
ovirt_vm:
name: "{{ vm_name }}"
state: running
boot_devices:
- hd
- name: Ensure Satellite is reachable
hosts: "{{ vm_name }}"
gather_facts: no
tasks:
- name: Set authentication for bootstrap
no_log: True
set_fact:
ansible_ssh_user: "root"
ansible_ssh_pass: "{{ initial_root_pass }}"
- name: Wait for SSH to be ready
wait_for_connection:
timeout: 1800
sleep: 5
- name: Register System to Red Hat
redhat_subscription:
state: present
username: "{{ rhn_username }}"
password: "{{ rhn_password }}"
# TODO This shouldn't be hard-coded
pool_ids: 8a85f99c727637ad0172e1ba2856736d
- name: Set up IPA Client
hosts: "{{ vm_name }}"
become: yes
vars:
ipaclient_realm: IDM.TOAL.CA
ipaclient_mkhomedir: true
ipaclient_domain: "mgmt.toal.ca"
ipasssd_enable_dns_updates: true
collections:
- freeipa.ansible_freeipa
pre_tasks:
- name: Set hostname
hostname:
name: "{{ vm_name }}"
roles:
- role: debian-freeipa-client
when: ansible_os_family == "Debian"
- role: ipaclient
state: present
when: ansible_os_family == "RedHat"
- name: Set up Basic Lab Packages
hosts: "{{ vm_name }}"
become: yes
roles:
- role: toal-common
- name: Configure Satellite Servers
hosts: "{{ vm_name }}"
become: true