"Fossies" - the Fresh Open Source Software Archive

Member "ansible-6.1.0/ansible_collections/ovirt/ovirt/roles/hosted_engine_setup/tasks/bootstrap_local_vm/02_create_local_vm.yml" (9 Jun 2022, 6431 Bytes) of package /linux/misc/ansible-6.1.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Ansible YAML source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "02_create_local_vm.yml": 5.9.0_vs_6.0.0.

    1 ---
    2 - name: Create hosted engine local vm
    3   block:
    4   - name: Initial tasks
    5     block:
    6       - name: Get host unique id
    7         shell: |
    8           if [ -e /etc/vdsm/vdsm.id ];
    9           then cat /etc/vdsm/vdsm.id;
   10           elif [ -e /proc/device-tree/system-id ];
   11           then cat /proc/device-tree/system-id; #ppc64le
   12           else dmidecode -s system-uuid;
   13           fi;
   14         environment: "{{ he_cmd_lang }}"
   15         changed_when: true
   16         register: unique_id_out
   17       - name: Create directory for local VM
   18         tempfile:
   19           state: directory
   20           path: "{{ he_local_vm_dir_path }}"
   21           prefix: "{{ he_local_vm_dir_prefix }}"
   22         register: otopi_localvm_dir
   23       - name: Set local vm dir path
   24         set_fact:
   25           he_local_vm_dir: "{{ otopi_localvm_dir.path }}"
   26       - include_tasks: ../install_appliance.yml
   27         when: he_appliance_ova is none or he_appliance_ova|length == 0
   28       - name: Register appliance PATH
   29         set_fact:
   30           he_appliance_ova_path: "{{ he_appliance_ova }}"
   31         when: he_appliance_ova is not none and he_appliance_ova|length > 0
   32       - debug: var=he_appliance_ova_path
   33       - name: Check available space on local VM directory
   34         shell: df -k --output=avail "{{ he_local_vm_dir_path }}" | grep -v Avail | cat
   35         environment: "{{ he_cmd_lang }}"
   36         changed_when: true
   37         register: local_vm_dir_space_out
   38       - name: Check appliance size
   39         shell: zcat "{{ he_appliance_ova_path }}" | wc --bytes
   40         environment: "{{ he_cmd_lang }}"
   41         changed_when: true
   42         register: appliance_size
   43       - name: Ensure we have enough space to extract the appliance
   44         assert:
   45           that:
   46             - "local_vm_dir_space_out.stdout_lines[0]|int * 1024 > appliance_size.stdout_lines[0]|int * 1.1"
   47           msg: >
   48             {{ he_local_vm_dir_path }} doesn't provide enough free space to extract the
   49             engine appliance: {{ local_vm_dir_space_out.stdout_lines[0]|int / 1024 | int }} Mb
   50             are available while {{ appliance_size.stdout_lines[0]|int / 1024 / 1024 * 1.1 | int }} Mb
   51             are required.
   52       - name: Extract appliance to local VM directory
   53         unarchive:
   54           remote_src: true
   55           src: "{{ he_appliance_ova_path }}"
   56           dest: "{{ he_local_vm_dir }}"
   57           extra_opts: ['--sparse']
   58       - include_tasks: ../get_local_vm_disk_path.yml
   59       - name: Get appliance disk size
   60         command: qemu-img info --output=json {{ local_vm_disk_path }}
   61         environment: "{{ he_cmd_lang }}"
   62         changed_when: true
   63         register: qemu_img_out
   64       - debug: var=qemu_img_out
   65       - name: Parse qemu-img output
   66         set_fact:
   67           virtual_size={{ qemu_img_out.stdout|from_json|ovirt.ovirt.json_query('"virtual-size"') }}
   68         register: otopi_appliance_disk_size
   69       - debug: var=virtual_size
   70       - name: Hash the appliance root password
   71         set_fact:
   72           he_hashed_appliance_password: "{{ he_appliance_password | string | password_hash('sha512') }}"
   73         no_log: true
   74       - name: Create cloud init user-data and meta-data files
   75         template:
   76           src: "{{ item.src }}"
   77           dest: "{{ item.dest }}"
   78           mode: 0640
   79         with_items:
   80           - {src: templates/user-data.j2, dest: "{{ he_local_vm_dir }}/user-data"}
   81           - {src: templates/meta-data.j2, dest: "{{ he_local_vm_dir }}/meta-data"}
   82           - {src: templates/network-config-dhcp.j2, dest: "{{ he_local_vm_dir }}/network-config"}
   83       - name: Create ISO disk
   84         command: >-
   85           mkisofs -output {{ he_local_vm_dir }}/seed.iso -volid cidata -joliet -rock -input-charset utf-8
   86           {{ he_local_vm_dir }}/meta-data {{ he_local_vm_dir }}/user-data
   87           {{ he_local_vm_dir }}/network-config
   88         environment: "{{ he_cmd_lang }}"
   89         changed_when: true
   90       - name: Fix local VM directory permission
   91         file:
   92           state: directory
   93           path: "{{ he_local_vm_dir }}"
   94           owner: vdsm
   95           group: qemu
   96           recurse: yes
   97           mode: u=rwX,g=rwX,o=
   98       - name: Create local VM
   99         command: >-
  100           virt-install -n {{ he_vm_name }}Local --os-variant rhel8.0 --virt-type kvm --memory {{ he_mem_size_MB }}
  101           --vcpus {{ he_vcpus }}  --network network=default,mac={{ he_vm_mac_addr }},model=virtio
  102           --disk {{ local_vm_disk_path }} --import --disk path={{ he_local_vm_dir }}/seed.iso,device=cdrom
  103           --noautoconsole --rng /dev/random --graphics vnc --video vga --sound none --controller usb,model=none
  104           --memballoon none --boot hd,menu=off --clock kvmclock_present=yes
  105         environment: "{{ he_cmd_lang }}"
  106         register: create_local_vm
  107         changed_when: true
  108       - debug: var=create_local_vm
  109       - name: Get local VM IP
  110         shell: virsh -r net-dhcp-leases default | grep -i {{ he_vm_mac_addr }} | awk '{ print $5 }' | cut -f1 -d'/'
  111         environment: "{{ he_cmd_lang }}"
  112         register: local_vm_ip
  113         until: local_vm_ip.stdout_lines|length >= 1
  114         retries: 90
  115         delay: 10
  116         changed_when: true
  117       - debug: var=local_vm_ip
  118       - name: Remove leftover entries in /etc/hosts for the local VM
  119         lineinfile:
  120           dest: /etc/hosts
  121           regexp: "# temporary entry added by hosted-engine-setup for the bootstrap VM$"
  122           state: absent
  123       - name: Create an entry in /etc/hosts for the local VM
  124         lineinfile:
  125           dest: /etc/hosts
  126           line:
  127             "{{ local_vm_ip.stdout_lines[0] }} \
  128             {{ he_fqdn }} # temporary entry added by hosted-engine-setup for the bootstrap VM"
  129           insertbefore: BOF
  130           backup: true
  131       - name: Wait for SSH to restart on the local VM
  132         wait_for:
  133           host='{{ he_fqdn }}'
  134           port=22
  135           delay=30
  136           timeout=300
  137       - name: Set the name for add_host
  138         set_fact:
  139           he_fqdn_ansible_host: "{{ local_vm_ip.stdout_lines[0] }}"
  140       - import_tasks: ../add_engine_as_ansible_host.yml
  141     rescue:
  142       - include_tasks: ../clean_localvm_dir.yml
  143       - include_tasks: ../clean_local_storage_pools.yml
  144       - name: Notify the user about a failure
  145         fail:
  146           msg: >
  147             The system may not be provisioned according to the playbook
  148             results: please check the logs for the issue,
  149             fix accordingly or re-deploy from scratch.