0

I have two problems when configuring the network of a virtual machine already created. I hava this code:

  - name: Creates a new Virtual Machine from template named 'rhel7_template'
      ovirt_vm:
        auth: "{{ ovirt_auth }}"
        state: present
        name: testaes02
        template: tmpl-rhv-dc20-rhel-7
        cluster: KVM_DC_20_CL_LC_Linux_01

    - ovirt_nic_info:
        auth: "{{ ovirt_auth }}"
        vm: testaes01
      register: result
    - debug:
        msg: "{{ result.ovirt_nics[0].reported_devices[0].name }}"



    - name: Run VM with cloud init
      ovirt_vm:
        auth: "{{ ovirt_auth }}"
        name: testaes01
        cloud_init:
          custom_script: |
            write_files:
             - path: /etc/sysconfig/network-scripts/ "{{ result.ovirt_nics[0].reported_devices[0].name }}"
               content: |
                          DEVICE="eth0"
                          NM_CONTROLLED="yes"
                          ONBOOT=yes
                          TYPE=Ethernet
                          BOOTPROTO=none
                          IPADDR=192.168.80.156
                          GATEWAY=192.168.80.1
                          NETMASK=255.255.255.0
                          DOMAIN="inf.sta da.inf.sta"
                          DEFROUTE=yes
                          IPV4_FAILURE_FATAL=yes
                          IPV6INIT=no


            runcmd:
             - /etc/sysconfig/network-scripts/ "{{ result.ovirt_nics[0].reported_devices[0].name }}"
             - command systemctl restart network
          user_name: root
          root_password: super_password

My problem is that no add config network in the network file.

I would also like to know if there is something similar to the vmware_vm_shell module for Ovirt

  • Would try add `cloud_init_persist: true` or `state: running` and maybe also check cloud_init_nics. There isn't anything like vmware_vm_shell for ovirt because after you configure the vm and get ip you can run normal ansible task on it. Hopefully helps if not don't hesitate to create issue on https://github.com/ovirt/ovirt-ansible-collection (I'm not so active on StackOverflow) – Martin Nečas May 21 '20 at 18:00
  • Also, check if you have installed on the VM cloud-init. – Martin Nečas Jun 04 '20 at 09:18

0 Answers0