Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmware.vmware_rest.vcenter_vm_guest_customization module Documentation #527

Open
1 task done
mgamboa opened this issue Sep 9, 2024 · 3 comments
Open
1 task done
Assignees
Labels
documentation Improvements or additions to documentation has_pr

Comments

@mgamboa
Copy link

mgamboa commented Sep 9, 2024

Summary

I was trying the module and when running with the example fail the reason was missing the 3 variables that are required, they come documented but in the example is no show how to use it

Issue Type

Documentation Report

Component Name

vmware.vmware_rest.vcenter_vm_guest_customization module

Ansible Version

$ ansible --version
2.15

Collection Versions

$ ansible-galaxy collection list

Configuration

$ ansible-config dump --only-changed

OS / Environment

AWX

Additional Information

No response

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@mikemorency mikemorency added the documentation Improvements or additions to documentation label Sep 9, 2024
@mikemorency
Copy link
Collaborator

hi @mgamboa

Are you talking about the parameters vcenter_hostname, vcenter_username, and vcenter_password? Those parameters are used for authentication to your vCenter cluster. You need to specify some values, but you can set them as environment variables (as described here) or as parameters when using the module.

Ill wait for you to confirm that is what your talking about, but in the meantime here is an example where they are defined as parameters while using the module.

- name: Customize the VM
  vmware.vmware_rest.vcenter_vm_guest_customization:
    vcenter_hostname: my-vcenter.domain.local
    vcenter_username: administrator@vsphere.local
    vcenter_password: SuperSecretPass
    vm: "{{ lookup('vmware.vmware_rest.vm_moid', '/my_dc/vm/test_vm1') }}"
    configuration_spec:
      linux_config:
        domain: mydomain
        hostname:
          fixed_name: foobar
          type: FIXED
    interfaces:
    - adapter:
        ipv4:
          type: STATIC
          gateways:
          - 192.168.123.1
          ip_address: 192.168.123.50
          prefix: 24
    global_DNS_settings:
      dns_suffix_list: []
      dns_servers:
      - 1.1.1.1

@mgamboa
Copy link
Author

mgamboa commented Sep 10, 2024 via email

@mikemorency
Copy link
Collaborator

Hello, Ive opened a PR to update the documentation examples for this module. Heres the current version, please let me know your thoughts here or in the PR

##########
#
# VM customization can be difficult to troubleshoot, since each environment is different. Here are some general tips:
#
# 1. Make sure perl is installed on the Linux systems. Make sure cloud-init is installed if using cloud-init
# 2. Custom script execution is disabled by default. To enable it, you can run as root: vmware-toolbox-cmd config set deployPkg enable-custom-scripts  true
# 3. VMware tools must be installed and recognized by vCenter before you can apply customization. See the example below for one approach to this.
# 4. On Linux (RHEL specifically), customization script logs can be found at /var/log/vmware-imc/toolsDeployPkg.log
# 5. Once the VM is started, the pending customization is applied. Even if that fails, the customization is then cleared. Meaning, you need to re-apply
#    the customization spec in order to try again. Simply rebooting the VM will not change anything.
#
##########

# Heres the basic workflow for creating a new VM and then customizing it
- name: Deploy a new VM based on a template
  vmware.vmware_rest.vcenter_vmtemplate_libraryitems:
    name: vm-from-template
    library: '{{ library_id }}'
    template_library_item: '{{ template_id }}'
    placement:
      cluster: "{{ lookup('vmware.vmware_rest.cluster_moid', '/my_dc/host/my_cluster') }}"
    state: deploy
  register: my_new_vm

- name: Power on the VM to register VMware tools
  vmware.vmware_rest.vcenter_vm_power:
    state: start
    vm: "{{ my_new_vm.id }}"

- name: Wait until my VMware tools are recognized
  vmware.vmware_rest.vcenter_vm_tools_info:
    vm: "{{ my_new_vm.id }}"
  register: vm_tools_info
  until:
    - vm_tools_info is not failed
    - vm_tools_info.value.run_state == "RUNNING"
  retries: 60
  delay: 5

- name: Power Off VM
  vmware.vmware_rest.vcenter_vm_power:
    state: stop
    vm: "{{ my_new_vm.id }}"

- name: Customize the VM
    vmware.vmware_rest.vcenter_vm_guest_customization:
    vm: "{{ my_new_vm.id }}"
    global_DNS_settings:
      dns_suffix_list:
        - lan
        - foo.internal
      dns_servers:
        - "8.8.8.8"
    interfaces:
      - adapter:
          ipv4:
            type: DHCP
    configuration_spec:
      linux_config:
        domain: test
        hostname:
          fixed_name: myhost
          type: FIXED

# Heres an example using the Linux script text. The script shebang can be anything (bash, perl, python), so long as the script will actually run
# Theres also size and length limitation on the script text, as described in the module documentation.
# Finally, note the script is run twice. Once before all of the other customization and once after.
- name: Customize the VM
    vmware.vmware_rest.vcenter_vm_guest_customization:
    vm: "{{ my_new_vm.id }}"
    global_DNS_settings:
      dns_suffix_list:
        - lan
        - foo.internal
      dns_servers:
        - "8.8.8.8"
    interfaces:
      - adapter:
          ipv4:
            type: DHCP
    configuration_spec:
      linux_config:
        domain: test
        hostname:
          fixed_name: myhost
          type: FIXED
        script_text: |
          #!/bin/sh
          if [ x$1 == x"precustomization" ]; then
            echo "PRE" >> /tmp/vmware_rest_init_script.log
            # add any other pre-customization tasks here
          fi

          if [ x$1 == x"postcustomization" ]; then
            echo "POST" >> /tmp/vmware_rest_init_script.log
            # add any other post-customization tasks here
          fi


# Heres an example using cloud-init
# See also:
#   https://developer.broadcom.com/xapis/vsphere-automation-api/latest/vcenter/data-structures/Guest_CloudinitConfiguration/
#   https://knowledge.broadcom.com/external/article/311895/how-to-customize-virtual-machine-using-c.html
#   https://cloudinit.readthedocs.io/en/latest/reference/examples.html

- name: Customize the VM
    vmware.vmware_rest.vcenter_vm_guest_customization:
    vm: "{{ my_new_vm.id }}"
    global_DNS_settings:
      dns_suffix_list: []
      dns_servers:
        - "8.8.8.8"
    interfaces:
      - adapter:
          ipv4:
          type: DHCP
    configuration_spec:
      cloud_config:
        type: CLOUDINIT
        cloudinit:
          metadata: |
            instance-id: cloud-vm-example-1
            local-hostname: cloud-vm
            network:
              config: disabled
          userdata: |
            #cloud-config
            disable_root: 0
            write_files:
              - content: |
                  This is a test
                path: /root/cloud-init-example

@mikemorency mikemorency self-assigned this Sep 25, 2024
softwarefactory-project-zuul bot pushed a commit that referenced this issue Sep 30, 2024
SUMMARY
Updates the examples in the vm customization module to be more detailed and cover both the linux and cloud-init configuration schemes.
Fixes
#472
#527
ISSUE TYPE

Docs Pull Request

COMPONENT NAME
vcenter_vm_guest_customization

Reviewed-by: Danielle Barda
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation has_pr
Projects
None yet
Development

No branches or pull requests

2 participants