From b71637940046667a11ad69f817892542b773b728 Mon Sep 17 00:00:00 2001 From: Mohammed Ahmed Date: Wed, 24 Jan 2024 17:58:06 +0530 Subject: [PATCH] Adding optional port for file server. (#238) This allows user to have his file server running on non-standard port. Signed-off-by: Mohammed Zeeshan Ahmed fix #221 Signed-off-by: Mohammed Zeeshan Ahmed --- docs/set-variables-group-vars.md | 1 + inventories/default/group_vars/all.yaml.template | 1 + roles/create_bastion/tasks/main.yaml | 2 +- roles/create_bastion/templates/bastion-ks.cfg.j2 | 6 +++--- roles/create_bastion_hypershift/tasks/main.yaml | 8 ++++---- roles/create_kvm_host/tasks/main.yaml | 2 +- roles/disconnected_mirror_images/tasks/main.yaml | 2 +- roles/update_cfgs/templates/kvm_host.cfg.j2 | 2 +- roles/update_cfgs/templates/kvm_host.prm.j2 | 4 ++-- 9 files changed, 15 insertions(+), 13 deletions(-) diff --git a/docs/set-variables-group-vars.md b/docs/set-variables-group-vars.md index a430f2d4..269f1232 100644 --- a/docs/set-variables-group-vars.md +++ b/docs/set-variables-group-vars.md @@ -37,6 +37,7 @@ **Variable Name** | **Description** | **Example** :--- | :--- | :--- **env.file_server.ip** | IPv4 address for the file server that will be used to pass config files and
iso to KVM host LPAR(s) and bastion VM during their first boot. | 192.168.10.201 +**env.file_server.port** | The port on which the file server is listening. Will be embedded into all
download urls. Defaults to protocol default port. Keep empty `''` to use
default port | 10000 **env.file_server.user** | Username to connect to the file server. Must have sudo and SSH access. | user1 **env.file_server.pass** | Password to connect to the file server as above user. | user1pa$s! **env.file_server.protocol** | Protocol used to serve the files, either 'ftp' or 'http' | http diff --git a/inventories/default/group_vars/all.yaml.template b/inventories/default/group_vars/all.yaml.template index dca3154d..bdf011ec 100644 --- a/inventories/default/group_vars/all.yaml.template +++ b/inventories/default/group_vars/all.yaml.template @@ -34,6 +34,7 @@ env: # Section 3 - File Server file_server: ip: #X + port: '' # please keep empty string to use default port user: #X pass: #X protocol: #X diff --git a/roles/create_bastion/tasks/main.yaml b/roles/create_bastion/tasks/main.yaml index 9331d212..d2e33a5d 100644 --- a/roles/create_bastion/tasks/main.yaml +++ b/roles/create_bastion/tasks/main.yaml @@ -63,7 +63,7 @@ --autostart \ --memory={{ env.bastion.resources.ram }} \ --vcpus={{ env.bastion.resources.vcpu }} \ - --location {{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}/{{ env.file_server.iso_mount_dir }} \ + --location {{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}{{ ':' + env.file_server.port if env.file_server.port | default('') | length > 0 else '' }}/{{ env.file_server.iso_mount_dir }} \ --disk pool={{ env.cluster.networking.metadata_name }}-vdisk,size={{ env.bastion.resources.disk_size }} \ --network network={{ env.bridge_name }} \ --graphics none \ diff --git a/roles/create_bastion/templates/bastion-ks.cfg.j2 b/roles/create_bastion/templates/bastion-ks.cfg.j2 index 3ffdab71..ab9b6d9f 100644 --- a/roles/create_bastion/templates/bastion-ks.cfg.j2 +++ b/roles/create_bastion/templates/bastion-ks.cfg.j2 @@ -14,11 +14,11 @@ text --non-interactive firstboot --enable # Use network installation -url --url={{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}/{{ env.file_server.iso_mount_dir }} +url --url={{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}{{ ':' + env.file_server.port if env.file_server.port | default('') | length > 0 else '' }}/{{ env.file_server.iso_mount_dir }} # Add yum repositories -repo --install --name="AppStream" --baseurl={{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}/{{ env.file_server.iso_mount_dir }}/AppStream/ -repo --install --name="BaseOS" --baseurl={{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}/{{ env.file_server.iso_mount_dir }}/BaseOS/ +repo --install --name="AppStream" --baseurl={{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}{{ ':' + env.file_server.port if env.file_server.port | default('') | length > 0 else '' }}/{{ env.file_server.iso_mount_dir }}/AppStream/ +repo --install --name="BaseOS" --baseurl={{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}{{ ':' + env.file_server.port if env.file_server.port | default('') | length > 0 else '' }}/{{ env.file_server.iso_mount_dir }}/BaseOS/ # Keyboard layouts keyboard --vckeymap={{ env.keyboard }} --xlayouts='{{ env.keyboard }}' diff --git a/roles/create_bastion_hypershift/tasks/main.yaml b/roles/create_bastion_hypershift/tasks/main.yaml index 7691b32f..8dba3b15 100644 --- a/roles/create_bastion_hypershift/tasks/main.yaml +++ b/roles/create_bastion_hypershift/tasks/main.yaml @@ -9,7 +9,7 @@ ssh_key: "{{ ssh_output.stdout_lines[0] }}" - name: Create Directory for images and bastion.ks - file: + file: path: /home/libvirt/images/ recurse: true state: directory @@ -50,16 +50,16 @@ - name: Create qemu image for bastion command: qemu-img create -f qcow2 /home/libvirt/images/{{ hypershift.hcp.hosted_cluster_name }}-bastion.qcow2 100G -- name: Create bastion +- name: Create bastion shell: | - virt-install \ + virt-install \ --name {{ hypershift.hcp.hosted_cluster_name }}-bastion \ --memory 4096 \ --vcpus sockets=1,cores=4,threads=1 \ --disk /home/libvirt/images/{{ hypershift.hcp.hosted_cluster_name }}-bastion.qcow2,format=qcow2,bus=virtio,cache=none \ --os-variant "rhel{{hypershift.bastion_parms.os_variant}}" \ --network network:{{ env.bridge_name }} \ - --location '{{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}/{{ env.file_server.iso_mount_dir }}/' \ + --location '{{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}{{ ':' + env.file_server.port if env.file_server.port | default('') | length > 0 else '' }}/{{ env.file_server.iso_mount_dir }}/' \ --rng=/dev/urandom --initrd-inject /home/libvirt/bastion.ks \ --extra-args="ks=file:/bastion.ks ip={{ hypershift.bastion_hypershift }}::{{hypershift.bastion_parms.gateway}}:{{hypershift.bastion_parms.subnet_mask}}:{{ hypershift.bastion_parms.hostname }}.{{ hypershift.bastion_parms.base_domain }}:{{ hypershift.bastion_parms.interface }}:none console=ttysclp0 nameserver={{hypershift.bastion_parms.nameserver}}" \ --noautoconsole \ diff --git a/roles/create_kvm_host/tasks/main.yaml b/roles/create_kvm_host/tasks/main.yaml index 210298ad..12e9a039 100644 --- a/roles/create_kvm_host/tasks/main.yaml +++ b/roles/create_kvm_host/tasks/main.yaml @@ -11,7 +11,7 @@ cpc_name: "{{ cpc_name }}" name: "{{ lpar.name }}" properties: - boot_ftp_host: "{{ env.file_server.ip }}" + boot_ftp_host: "{{ env.file_server.ip }}{{ ':' + env.file_server.port if env.file_server.port | default('') | length > 0 else '' }}" boot_ftp_username: "{{ env.file_server.user }}" boot_ftp_password: "{{ env.file_server.pass }}" boot_ftp_insfile: "{{ env.file_server.cfgs_dir }}/{{ networking.hostname }}/kvm_host.ins" diff --git a/roles/disconnected_mirror_images/tasks/main.yaml b/roles/disconnected_mirror_images/tasks/main.yaml index 1690a74d..26bd6cc0 100644 --- a/roles/disconnected_mirror_images/tasks/main.yaml +++ b/roles/disconnected_mirror_images/tasks/main.yaml @@ -27,7 +27,7 @@ remote_src: yes loop: - "{{ disconnected.mirroring.client_download.ocp_download_url }}{{ disconnected.mirroring.client_download.ocp_client_tgz }}" - - "{{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}/{{ disconnected.mirroring.file_server.clients_dir }}/{{ disconnected.mirroring.file_server.oc_mirror_tgz }}" + - "{{ env.file_server.protocol }}://{{ env.file_server.user + ':' + env.file_server.pass + '@' if env.file_server.protocol == 'ftp' else '' }}{{ env.file_server.ip }}{{ ':' + env.file_server.port if env.file_server.port | default('') | length > 0 else '' }}/{{ disconnected.mirroring.file_server.clients_dir }}/{{ disconnected.mirroring.file_server.oc_mirror_tgz }}" - name: Copy kubectl, oc, and oc-mirror binaries to /usr/local/sbin tags: mirror_artifacts become: true diff --git a/roles/update_cfgs/templates/kvm_host.cfg.j2 b/roles/update_cfgs/templates/kvm_host.cfg.j2 index 903d7ba4..41ea383f 100644 --- a/roles/update_cfgs/templates/kvm_host.cfg.j2 +++ b/roles/update_cfgs/templates/kvm_host.cfg.j2 @@ -15,7 +15,7 @@ dd if=/dev/zero of=/dev/mapper/mpathh bs=512 count=10 reboot # Use network installation -url --url=ftp://{{env.file_server.user}}:{{env.file_server.pass}}@{{env.file_server.ip}}/{{ env.file_server.iso_mount_dir }} +url --url=ftp://{{env.file_server.user}}:{{env.file_server.pass}}@{{env.file_server.ip}}{{ ':' + env.file_server.port if env.file_server.port | default('') | length > 0 else '' }}/{{ env.file_server.iso_mount_dir }} # Use text mode install text diff --git a/roles/update_cfgs/templates/kvm_host.prm.j2 b/roles/update_cfgs/templates/kvm_host.prm.j2 index 06a6f7e9..2cd6d3ee 100644 --- a/roles/update_cfgs/templates/kvm_host.prm.j2 +++ b/roles/update_cfgs/templates/kvm_host.prm.j2 @@ -1,6 +1,6 @@ ro ramdisk_size=40000 ip={{ networking.ip }}::{{ networking.gateway }}:{{ lpar.networking.subnet_cidr }}:{{ networking.hostname}}:{{ networking.device1 }}:none nameserver={{ networking.nameserver1 }} {{ ( 'nameserver=' + networking.nameserver2 ) if networking.nameserver2 is defined else '' }} -inst.repo=ftp://{{ env.file_server.user }}:{{ env.file_server.pass }}@{{ env.file_server.ip }}/{{ env.file_server.iso_mount_dir }} -inst.ks=ftp://{{ env.file_server.user }}:{{ env.file_server.pass }}@{{ env.file_server.ip }}/{{ env.file_server.cfgs_dir }}/{{ networking.hostname }}/kvm_host.cfg +inst.repo=ftp://{{ env.file_server.user }}:{{ env.file_server.pass }}@{{ env.file_server.ip }}{{ ':' + env.file_server.port if env.file_server.port | default('') | length > 0 else '' }}/{{ env.file_server.iso_mount_dir }} +inst.ks=ftp://{{ env.file_server.user }}:{{ env.file_server.pass }}@{{ env.file_server.ip }}{{ ':' + env.file_server.port if env.file_server.port | default('') | length > 0 else '' }}/{{ env.file_server.cfgs_dir }}/{{ networking.hostname }}/kvm_host.cfg inst.cmdline