#690 metrics: Added command to create a kvm vm configured to use pxeboot
Merged 2 years ago by dkirwan. Opened 2 years ago by dkirwan.
fedora-infra/ dkirwan/ansible main  into  main

file modified
+16
@@ -87,6 +87,22 @@ 

  mac_address: RANDOM

  mac_address1: RANDOM

  

+ 

+ virt_install_command_pxe_rhcos: virt-install \

+   --name {{ inventory_hostname }} \

+   --vcpus {{ num_cpus }},maxvcpus={{ max_cpu }} \

+   --cpu host \

+   --memory  {{ mem_size }} \

+   --disk bus=virtio,path={{ volgroup }}/{{ inventory_hostname }} \

+   --nographics \

+   --network bridge={{ main_bridge }},model=virtio,mac={{ mac_address }} \

+   --hvm --accelerate \

+   --autostart --wait=-1 \

+   --extra-args "ip={{ eth0_ip }}::{{ gw }}:{{ nm }}:{{ inventory_hostname }}:eth0:none nameserver={{ dns }} console=ttyS0 nomodeset rd.neednet=1 coreos.inst=yes coreos.inst.install_dev=vda coreos.live.rootfs_url={{ rhcos_install_rootfs_url }} coreos.inst.ignition_url={{ rhcos_ignition_file_url }} " \

+   --os-type linux --os-variant rhel7 \

+   --location  {{ rhcos_install_url }}

+ 

+ 

  virt_install_command_one_nic: virt-install -n {{ inventory_hostname }}

                   --memory={{ mem_size }},maxmemory={{ max_mem_size }} --memballoon virtio

                   --disk bus=virtio,path={{ volgroup }}/{{ inventory_hostname }}

@@ -0,0 +1,56 @@ 

+ ---

+ freezes: false

+  

+ datacenter: iad2

+  

+ vmhost: vmhost-x86-05.stg.iad2.fedoraproject.org

+ volgroup: /dev/vg_guests

+ lvm_size: 120g

+ mem_size: 16384

+ max_mem_size: 16384

+ num_cpus: 4

+  

+ dns1: 10.3.163.33

+ dns2: 10.3.163.34

+  

+ dns_search1: "stg.iad2.fedoraproject.org"

+ dns_search3: "fedoraproject.org"

+  

+ has_ipv4: yes

+ eth0_ipv4: 10.3.166.115

+ eth0_ipv4_nm: 24

+ eth0_ipv4_gw: 10.3.166.254 

+  

+ mac0: "{{ ansible_default_ipv4.macaddress }}"

+ 

+ rhcos_ignition_file_url: "http://10.3.166.50/rhcos/controlplane.ign"

+ rhcos_install_img_url: "http://10.3.166.50/rhcos/rhcos-{{ rhcos_version }}-x86_64-metal.x86_64.raw.gz"

+ rhcos_install_rootfs_url: "http://10.3.166.50/rhcos/rhcos-{{ rhcos_version }}-x86_64-live-rootfs.x86_64.img"

+ rhcos_install_url: "http://10.3.166.50/rhcos/"

+ 

+ virt_install_command: "{{ virt_install_command_pxe_rhcos }}"

+  

+ network_connections:

+   - name: eth0

+     mac: "{{ mac0 }}"

+     state: up

+     type: ethernet

+     autoconnect: yes

+     ip:

+       address:

+       - "{{ eth0_ipv4 }}/{{ eth0_ipv4_nm }}"

+       gateway4: "{{ eth0_ipv4_gw }}"

+       dns:

+       - "{{ dns1 }}"

+       - "{{ dns2 }}"

+       dns_search:

+       - "{{ dns_search1 }}"

+       - "{{ dns_search2 }}"

+       - "{{ dns_search3 }}"

+       dhcp4: no

+       auto6: no

+  

+ vpn: true

+  

+ nrpe_procs_warn: 1200

+ nrpe_procs_crit: 1400

@@ -0,0 +1,56 @@ 

+ ---

+ freezes: false

+  

+ datacenter: iad2

+  

+ vmhost: vmhost-x86-06.stg.iad2.fedoraproject.org

+ volgroup: /dev/vg_guests

+ lvm_size: 120g

+ mem_size: 16384

+ max_mem_size: 16384

+ num_cpus: 4

+  

+ dns1: 10.3.163.33

+ dns2: 10.3.163.34

+  

+ dns_search1: "stg.iad2.fedoraproject.org"

+ dns_search3: "fedoraproject.org"

+  

+ has_ipv4: yes

+ eth0_ipv4: 10.3.166.116

+ eth0_ipv4_nm: 24

+ eth0_ipv4_gw: 10.3.166.254 

+  

+ mac0: "{{ ansible_default_ipv4.macaddress }}"

+ 

+ rhcos_ignition_file_url: "http://10.3.166.50/rhcos/controlplane.ign"

+ rhcos_install_img_url: "http://10.3.166.50/rhcos/rhcos-{{ rhcos_version }}-x86_64-metal.x86_64.raw.gz"

+ rhcos_install_rootfs_url: "http://10.3.166.50/rhcos/rhcos-{{ rhcos_version }}-x86_64-live-rootfs.x86_64.img"

+ rhcos_install_url: "http://10.3.166.50/rhcos/"

+ 

+ virt_install_command: "{{ virt_install_command_pxe_rhcos }}"

+  

+ network_connections:

+   - name: eth0

+     mac: "{{ mac0 }}"

+     state: up

+     type: ethernet

+     autoconnect: yes

+     ip:

+       address:

+       - "{{ eth0_ipv4 }}/{{ eth0_ipv4_nm }}"

+       gateway4: "{{ eth0_ipv4_gw }}"

+       dns:

+       - "{{ dns1 }}"

+       - "{{ dns2 }}"

+       dns_search:

+       - "{{ dns_search1 }}"

+       - "{{ dns_search2 }}"

+       - "{{ dns_search3 }}"

+       dhcp4: no

+       auto6: no

+  

+ vpn: true

+  

+ nrpe_procs_warn: 1200

+ nrpe_procs_crit: 1400

@@ -0,0 +1,56 @@ 

+ ---

+ freezes: false

+  

+ datacenter: iad2

+  

+ vmhost: vmhost-x86-07.stg.iad2.fedoraproject.org

+ volgroup: /dev/vg_guests

+ lvm_size: 120g

+ mem_size: 16384

+ max_mem_size: 16384

+ num_cpus: 4

+  

+ dns1: 10.3.163.33

+ dns2: 10.3.163.34

+  

+ dns_search1: "stg.iad2.fedoraproject.org"

+ dns_search3: "fedoraproject.org"

+  

+ has_ipv4: yes

+ eth0_ipv4: 10.3.166.117

+ eth0_ipv4_nm: 24

+ eth0_ipv4_gw: 10.3.166.254 

+  

+ mac0: "{{ ansible_default_ipv4.macaddress }}"

+ 

+ rhcos_ignition_file_url: "http://10.3.166.50/rhcos/controlplane.ign"

+ rhcos_install_img_url: "http://10.3.166.50/rhcos/rhcos-{{ rhcos_version }}-x86_64-metal.x86_64.raw.gz"

+ rhcos_install_rootfs_url: "http://10.3.166.50/rhcos/rhcos-{{ rhcos_version }}-x86_64-live-rootfs.x86_64.img"

+ rhcos_install_url: "http://10.3.166.50/rhcos/"

+ 

+ virt_install_command: "{{ virt_install_command_pxe_rhcos }}"

+  

+ network_connections:

+   - name: eth0

+     mac: "{{ mac0 }}"

+     state: up

+     type: ethernet

+     autoconnect: yes

+     ip:

+       address:

+       - "{{ eth0_ipv4 }}/{{ eth0_ipv4_nm }}"

+       gateway4: "{{ eth0_ipv4_gw }}"

+       dns:

+       - "{{ dns1 }}"

+       - "{{ dns2 }}"

+       dns_search:

+       - "{{ dns_search1 }}"

+       - "{{ dns_search2 }}"

+       - "{{ dns_search3 }}"

+       dhcp4: no

+       auto6: no

+  

+ vpn: true

+  

+ nrpe_procs_warn: 1200

+ nrpe_procs_crit: 1400

@@ -0,0 +1,111 @@ 

+ ---

+ # This playbook is an ad-hoc task used to deploy kvm nodes for OCP4

+ # It used the following variables, declared through inventory (group/host vars):

+ #  rhcos_version: 4.5.6 # upstream version to fetch from mirror.openshift.com in local httpd dir for deployment

+ #  rhcos_install_img_url: # Where to grab rhcos install http://<host>/<path>/rhcos/rhcos-4.3.8-x86_64-metal.x86_64.raw.gz

+ #  rhcos_ignition_file_url: # where to find ignition file http://<host>/config/rhcos/bootstrap.ign #to be modified based on group or host level, for bootstrap, master, etc

+ #  rhcos_install_url: #where kernel/initrd.img and .treeinfo are to be found, internal

+ #  kvm_guest_vcpus:

+ #  kvm_guest_memory:

+ #  kvm_guest_disk_size:  #in GiB, not to be added, so example: 120

+ #  kvm_host_bridge: # which defined bridged to use for the guest vnic

+ #  kvm_guest_vnic: ens3

+ #  ip:

+ #  nameservers:

+ #    - 192.168.1.1

+ #    - 192.168.2.2

+ #  gateway  

+ #  deploy_host: # http server serving ignition files

+ - hosts: os-control01.stg.iad2.fedoraproject.org

+   user: root

+   gather_facts: false

+ 

+   tasks:

+     - block:

+         - name: == OCP KVM provisioning == Ensuring we have needed httpd dir

+           file: 

+             path: "/var/www/html/rhcos"

+             state: directory

+             mode: 0755

+         - name: == OCP KVM provisioning == Importing generated Ignition files

+           template: 

+             src: "/srv/web/infra/bigfiles/openshiftboot/{{ item }}"

+             dest: "/var/www/html/rhcos/{{ item }}"

+             mode: 0755

+           with_items:

+             - bootstrap.ign

+             - controlplane.ign

+             - worker.ign

+         - name: == OCP KVM provisioning == Downloading RHCOS deploy files

+           get_url:

+             dest: /var/www/html/rhcos/

+             mode: 0755

+             url: "https://mirror.openshift.com/pub/openshift-v4/dependencies/rhcos/latest/{{ rhcos_version }}/{{ item }}"

+           run_once: True  

+           with_items:

+             - "rhcos-{{ rhcos_version }}-x86_64-live-initramfs.x86_64.img"

+             - "rhcos-{{ rhcos_version }}-x86_64-live-kernel-x86_64"

+             - "rhcos-{{ rhcos_version }}-x86_64-live-rootfs.x86_64.img"

+             - "rhcos-{{ rhcos_version }}-x86_64-metal.x86_64.raw.gz"

+ 

+         - name: == OCP KVM provisioning == Ensuring symlink for correct version {{ rhcos_version }}

+           file:

+             state: link

+             src: "/var/www/html/rhcos/rhcos-{{ rhcos_version }}-x86_64-metal.x86_64.raw.gz"

+             dest: "/var/www/html/rhcos/rhcos-metal.raw"

+         - name: == OCP KVM provisioning == Creating needed treeinfo for virt-install --location

+           template:

+             src: ocp-treeinfo.j2

+             dest: /var/www/html/rhcos/.treeinfo

+             mode: 0644

+       tags:

+         - ignition

+         - repo

+ 

+     - name: == OCP KVM provisioning == Checking OCP Virtual Guest exist[s]

+       virt: 

+         name: "{{ inventory_hostname }}" 

+         state: running

+       ignore_errors: yes

+       no_log: True

+       delegate_to: "{{ kvm_host }}"

+       register: vm_exists

+       tags:

+         - kvm_deploy

+ 

+     - name: == OCP KVM provisioning == Creating temporary virt-install command

+       template: 

+         src: ../templates/ansible-virt-install-ocp.j2 

+         dest: "/var/lib/libvirt/virt-install-{{ inventory_hostname }}" 

+         mode: 0750 

+         owner: root 

+         group: root

+       delegate_to: "{{ kvm_host }}"

+       tags:

+         - kvm_deploy

+ 

+     - name: == OCP KVM provisioning == Deploying the OCP Virtual Guest[s]

+       command: "/var/lib/libvirt/virt-install-{{ inventory_hostname }}"

+       when: vm_exists is failed

+       delegate_to: "{{ kvm_host }}"

+       tags:

+         - kvm_deploy

+ 

+     - name: == OCP KVM provisioning == Waiting for sshd to be available on the deployed node

+       wait_for: 

+         port: 22 

+         host: "{{ ip }}"

+         timeout: 1200 

+       delegate_to: "{{ deploy_host }}"

+       when: vm_exists is failed

+       tags:

+         - kvm_deploy

+ 

+     - name: == OCP KVM provisioning == Ensuring we remove the templatized virt-install script

+       file:

+         path: "/var/lib/libvirt/virt-install-{{ inventory_hostname }}"

+         state: absent

+       delegate_to: "{{ kvm_host }}"

+       tags:

+         - kvm_deploy

+ 

metrics: Added hostvars for ocp4 control plane

Signed-off-by: David Kirwan dkirwan@redhat.com

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

Looks good at a quick glance. You will also want a playbook/manual/ocp-vm-deploy.yml or something...

with:

  • import_playbook: "/srv/web/infra/ansible/playbooks/include/virt-create.yml myhosts=ocpwhatevergroup"

that will run the virt-install and setup everything. I guess ignition takes over after that.

Oh, we don't want to use network_connections on vm's... since we can't know the mac in advance/have a way to get it after the install. ;(

Also, vpn can be false here. we don't do vpn in staging...

Kevin,

I am confused by your last comment. We use network_connections on all the proxies which are virtual machines. We also can set the mac address in the virt-install. So I told David to use network_connections as we HAD been using them on vm's for some time [PS. If things have changed since then.. my apologies to David for leading him into this.]

How were you filling in the mac? I guess:
run playbook with no mac and have it fail
figure out the mac, commit it and re-run?
The mac for a vm is going to change every install and be random. ;(

But... I played with it last night and realized I was being dumb... ansible has the mac. We should (for vm's only) stop defining mac, and just pass to network_connections:
- name: eth0
mac: "{{ ansible_default_ipv4.macaddress }}"

I'm going to make sure this is all working today and send an email about it.

rebased onto f3a9801d149811dfd424bb75d40f8a2a28da22c9

2 years ago

rebased onto 7f8449d599a4bccaed038cc88f1af24ba479bb77

2 years ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

rebased onto 4e4869a25231653f3d26a3507e2cdddca81892e7

2 years ago

Build failed. More information on how to proceed and troubleshoot errors available at https://fedoraproject.org/wiki/Zuul-based-ci

rebased onto 9f290b9

2 years ago

Pull-Request has been merged by dkirwan

2 years ago