XCP-ng
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Register
    • Login

    Deploy VMs using Ansible

    Scheduled Pinned Locked Moved Development
    29 Posts 14 Posters 18.7k Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B Offline
      bvitnik
      last edited by bvitnik

      A milestone has been achieved 😱 . All of my modules have been merged upstream. I've updated the first post with new info.

      That will most probably be all for Ansible 2.8. I'm keeping some improvements and possibly more modules for Ansible 2.9. Currently, I'm thinking about what other modules could be useful so I could implement them. Any suggestion or wish would be much appreciated.

      1 Reply Last reply Reply Quote 2
      • C Offline
        cmuzyunda
        last edited by

        Great news , i will test your module in our DR environment and will provide any feedbacks (good or bad ) , please bear with me .....

        1 Reply Last reply Reply Quote 1
        • jedimarcusJ Offline
          jedimarcus
          last edited by

          @bvitnik I can confirm the most simple of tasks where I used your module to create a new VM based on an existing template.

          I'm still figuring out how to use this best.

          Does setting an IP work on any template (e.g. Linux Ubuntu) with XenTools installed?

          MM

          1 Reply Last reply Reply Quote 0
          • B Offline
            bvitnik
            last edited by bvitnik

            @jedimarcus Network configuration (IP, subnet, gateway) only works for Windows guests because there is proper support for it in XenServer Guest Tools for Windows. There is no such support (as far as I know) in XenServer Guest Tools for *nix based systems. Unlike tools for Windows, tools for *nix based systems only contain a few xenstore tools and a daemon (xe-daemon) that collects OS metrics. There is no management agent.

            My idea is to write a proper agent for *nix based systems at some point but it won't be any time soon. Maybe Citrix (or Vates 😉 ?) will implement one before I do.

            For now, you can use custom based network configuration trough xenstore and custom scripts. It's described in Notes section of the module documentation.

            1 Reply Last reply Reply Quote 0
            • Ced76C Offline
              Ced76
              last edited by

              Hello all,

              I try to create a playbook to deploy a Windows Server 2016 VM.
              I see a lot of examples with this parameter : register: deploy.
              But there is no reference in the parameters guide. Maybe a mistake ?

              B 1 Reply Last reply Reply Quote 0
              • B Offline
                bvitnik @Ced76
                last edited by

                @Ced76 "register" is not a module parameter. It's Ansible task parameter. Take a look at Ansible documentation for registered variables:

                https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#registering-variables

                Basically what "register: deploy" does is that is says "define a variable called deploy and put a return value of the module in it". A return value of the module in this case are numerous VM facts you can find in "deploy.instance" (sub)variable. Registered variable is accessible in any subsequent task of the same play. Also "deploy" here is just a random name chosen. You can name your registered variables however you like.

                Ced76C 1 Reply Last reply Reply Quote 0
                • Ced76C Offline
                  Ced76 @bvitnik
                  last edited by Ced76

                  @bvitnik Understood. Sorry but i'm newbie on Ansible 🙂 Doesn't see that this variable was not in the xenxerver_guest module part.
                  I try to create a lab with these objectives :
                  1- Provision Windows Server 2016 VMs on XCP-NG (or XenServer) after building my own Windows Server 2016 template (using best practices)
                  2- Define some roles on these VMs (Active Directory, IIS, SQL Server etc.)

                  Hope it'll be possible ...

                  Thanks.

                  1 Reply Last reply Reply Quote 0
                  • Ced76C Offline
                    Ced76
                    last edited by

                    Hi all,

                    Working perfect ! I've deployed 4 VMs from a custom WS2016 template under XCP-NG (version 7.5) 🙂
                    Nothing to do : just press <Enter> to execute the script.

                    Here is my first version if people want to try 😉

                    ---
                    - name: Deploy Windows Server 2016
                      hosts: localhost
                      connection: local
                      vars_prompt:
                        - name: "XenServer_IP_var"
                          prompt: "Enter XenServer IP Address"
                          private: no
                          default: "***.***.***.***"
                        - name: "XenServer_user_var"
                          prompt: "Enter XenServer username"
                          private: no
                          default: "root"
                        - name: "XenServer_pass_var"
                          prompt: "Enter XenServer password"
                          private: yes
                      vars:
                        template_var: "Windows Server 2016 Template (64-bit)"
                        folder_var: "Ansible Build Lab"
                        validate_certs_var : no
                        state_var: poweredon
                        linked_clone_var: yes
                        VMs_var:
                          - guest_var: "Lab-AD1"
                            hardware_var:
                              num_CPU_var: 1
                              num_CPU_cores_per_socket_var: 1
                              memory_MB_var: 4096
                            disk_var:
                              disk1_var:
                                size_var: 50
                                name_var: "Lab-AD1 : SYSTEM"
                              disk2_var:
                                size_var: 4
                                name_var: "Lab-AD1 : PAGEFILE"
                            network_var:
                              name_var: "VLAN 801"
                              type_var: "static"
                              ip_var: "***.***.***.***"
                              netmask_var: "***.***.***.***"
                              gateway_var: "***.***.***.***"
                          - guest_var: "Lab-BTS1"
                            hardware_var:
                              num_CPU_var: 2
                              num_CPU_cores_per_socket_var: 1
                              memory_MB_var: 8192
                            disk_var:
                              disk1_var:
                                size_var: 50
                                name_var: "Lab-BTS1 : SYSTEM"
                              disk2_var:
                                size_var: 4
                                name_var: "Lab-BTS1 : PAGEFILE"
                            network_var:
                              name_var: "VLAN 801"
                              type_var: "static"
                              ip_var: "***.***.***.***"
                              netmask_var: "***.***.***.***"
                              gateway_var: "***.***.***.***"
                          - guest_var: "Lab-IIS1"
                            hardware_var:
                              num_CPU_var: 1
                              num_CPU_cores_per_socket_var: 1
                              memory_MB_var: 4096
                            disk_var:
                              disk1_var:
                                size_var: 50
                                name_var: "Lab-IIS1 : SYSTEM"
                              disk2_var:
                                size_var: 4
                                name_var: "Lab-IIS1 : PAGEFILE"
                            network_var:
                              name_var: "VLAN 801"
                              type_var: "static"
                              ip_var: "***.***.***.***"
                              netmask_var: "***.***.***.***"
                              gateway_var: "***.***.***.***"
                          - guest_var: "Lab-SQL1"
                            hardware_var:
                              num_CPU_var: 2
                              num_CPU_cores_per_socket_var: 1
                              memory_MB_var: 8192
                            disk_var:
                              disk1_var:
                                size_var: 50
                                name_var: "Lab-SQL1 : SYSTEM"
                              disk2_var:
                                size_var: 4
                                name_var: "Lab-SQL1 : PAGEFILE"
                            network_var:
                              name_var: "VLAN 801"
                              type_var: "static"
                              ip_var: "***.***.***.***"
                              netmask_var: "***.***.***.***"
                              gateway_var: "***.***.***.***"
                        note_var: "Provisioned by Ansible"
                        SR_var: "Hardware HBA virtual disk storage"
                      tasks:
                        - name: Create VM Lab-AD1
                          xenserver_guest:
                            hostname: "{{ XenServer_IP_var }}"
                            username: "{{ XenServer_user_var }}"
                            password: "{{ XenServer_pass_var }}"
                            validate_certs: "{{ validate_certs_var }}"
                            folder: "{{ folder_var }}"
                            state: "{{ state_var }}"
                            template: "{{ template_var }}"
                            linked_clone: "{{ linked_clone_var }}"
                            name_desc: "{{ note_var }}"
                            name: "{{ item['guest_var'] }}"
                            disks:
                            - size_gb: "{{ item['disk_var']['disk1_var']['size_var'] }}"
                              name: "{{ item['disk_var']['disk1_var']['name_var'] }}"
                              sr: "{{ SR_var }}"
                            - size_gb: "{{ item['disk_var']['disk2_var']['size_var'] }}"
                              name: "{{ item['disk_var']['disk2_var']['name_var'] }}"
                              sr: "{{ SR_var }}"
                            hardware:
                              num_cpus: "{{ item['hardware_var']['num_CPU_var'] }}"
                              num_cpu_cores_per_socket: "{{ item['hardware_var']['num_CPU_cores_per_socket_var'] }}"
                              memory_mb: "{{ item['hardware_var']['memory_MB_var'] }}"
                            networks:
                            - name: "{{ item['network_var']['name_var'] }}"
                              type: "{{ item['network_var']['type_var'] }}"
                              ip: "{{ item['network_var']['ip_var'] }}"
                              netmask: "{{ item['network_var']['netmask_var'] }}"
                              gateway: "{{ item['network_var']['gateway_var'] }}"
                          with_items: "{{ VMs_var }}"
                          when: item['guest_var'] == "Lab-AD1"
                        - name: Create VM Lab-BTS1
                          xenserver_guest:
                            hostname: "{{ XenServer_IP_var }}"
                            username: "{{ XenServer_user_var }}"
                            password: "{{ XenServer_pass_var }}"
                            validate_certs: "{{ validate_certs_var }}"
                            folder: "{{ folder_var }}"
                            state: "{{ state_var }}"
                            template: "{{ template_var }}"
                            linked_clone: "{{ linked_clone_var }}"
                            name_desc: "{{ note_var }}"
                            name: "{{ item['guest_var'] }}"
                            disks:
                            - size_gb: "{{ item['disk_var']['disk1_var']['size_var'] }}"
                              name: "{{ item['disk_var']['disk1_var']['name_var'] }}"
                              sr: "{{ SR_var }}"
                            - size_gb: "{{ item['disk_var']['disk2_var']['size_var'] }}"
                              name: "{{ item['disk_var']['disk2_var']['name_var'] }}"
                              sr: "{{ SR_var }}"
                            hardware:
                              num_cpus: "{{ item['hardware_var']['num_CPU_var'] }}"
                              num_cpu_cores_per_socket: "{{ item['hardware_var']['num_CPU_cores_per_socket_var'] }}"
                              memory_mb: "{{ item['hardware_var']['memory_MB_var'] }}"
                            networks:
                            - name: "{{ item['network_var']['name_var'] }}"
                              type: "{{ item['network_var']['type_var'] }}"
                              ip: "{{ item['network_var']['ip_var'] }}"
                              netmask: "{{ item['network_var']['netmask_var'] }}"
                              gateway: "{{ item['network_var']['gateway_var'] }}"
                          with_items: "{{ VMs_var }}"
                          when: item['guest_var'] == "Lab-BTS1"
                        - name: Create VM Lab-IIS1
                          xenserver_guest:
                            hostname: "{{ XenServer_IP_var }}"
                            username: "{{ XenServer_user_var }}"
                            password: "{{ XenServer_pass_var }}"
                            validate_certs: "{{ validate_certs_var }}"
                            folder: "{{ folder_var }}"
                            state: "{{ state_var }}"
                            template: "{{ template_var }}"
                            linked_clone: "{{ linked_clone_var }}"
                            name_desc: "{{ note_var }}"
                            name: "{{ item['guest_var'] }}"
                            disks:
                            - size_gb: "{{ item['disk_var']['disk1_var']['size_var'] }}"
                              name: "{{ item['disk_var']['disk1_var']['name_var'] }}"
                              sr: "{{ SR_var }}"
                            - size_gb: "{{ item['disk_var']['disk2_var']['size_var'] }}"
                              name: "{{ item['disk_var']['disk2_var']['name_var'] }}"
                              sr: "{{ SR_var }}"
                            hardware:
                              num_cpus: "{{ item['hardware_var']['num_CPU_var'] }}"
                              num_cpu_cores_per_socket: "{{ item['hardware_var']['num_CPU_cores_per_socket_var'] }}"
                              memory_mb: "{{ item['hardware_var']['memory_MB_var'] }}"
                            networks:
                            - name: "{{ item['network_var']['name_var'] }}"
                              type: "{{ item['network_var']['type_var'] }}"
                              ip: "{{ item['network_var']['ip_var'] }}"
                              netmask: "{{ item['network_var']['netmask_var'] }}"
                              gateway: "{{ item['network_var']['gateway_var'] }}"
                          with_items: "{{ VMs_var }}"
                          when: item['guest_var'] == "Lab-IIS1"
                        - name: Create VM Lab-SQL1
                          xenserver_guest:
                            hostname: "{{ XenServer_IP_var }}"
                            username: "{{ XenServer_user_var }}"
                            password: "{{ XenServer_pass_var }}"
                            validate_certs: "{{ validate_certs_var }}"
                            folder: "{{ folder_var }}"
                            state: "{{ state_var }}"
                            template: "{{ template_var }}"
                            linked_clone: "{{ linked_clone_var }}"
                            name_desc: "{{ note_var }}"
                            name: "{{ item['guest_var'] }}"
                            disks:
                            - size_gb: "{{ item['disk_var']['disk1_var']['size_var'] }}"
                              name: "{{ item['disk_var']['disk1_var']['name_var'] }}"
                              sr: "{{ SR_var }}"
                            - size_gb: "{{ item['disk_var']['disk2_var']['size_var'] }}"
                              name: "{{ item['disk_var']['disk2_var']['name_var'] }}"
                              sr: "{{ SR_var }}"
                            hardware:
                              num_cpus: "{{ item['hardware_var']['num_CPU_var'] }}"
                              num_cpu_cores_per_socket: "{{ item['hardware_var']['num_CPU_cores_per_socket_var'] }}"
                              memory_mb: "{{ item['hardware_var']['memory_MB_var'] }}"
                            networks:
                            - name: "{{ item['network_var']['name_var'] }}"
                              type: "{{ item['network_var']['type_var'] }}"
                              ip: "{{ item['network_var']['ip_var'] }}"
                              netmask: "{{ item['network_var']['netmask_var'] }}"
                              gateway: "{{ item['network_var']['gateway_var'] }}"
                          with_items: "{{ VMs_var }}"
                          when: item['guest_var'] == "Lab-SQL1"
                    
                    A 1 Reply Last reply Reply Quote 3
                    • RelNetDavidMerrillR Offline
                      RelNetDavidMerrill
                      last edited by

                      Thanks for sharing!

                      1 Reply Last reply Reply Quote 1
                      • A Offline
                        AllooTikeeChaat @Ced76
                        last edited by

                        @Ced76

                        Ced thanks for the script.

                        1 Reply Last reply Reply Quote 0
                        • L Offline
                          Logo
                          last edited by

                          This post is deleted!
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post