-
Notifications
You must be signed in to change notification settings - Fork 341
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
Adding GuestOs Customization for Instant Clone feature #796
Adding GuestOs Customization for Instant Clone feature #796
Conversation
Thanks @Anant99-sys for the contribution. |
Could you please also add a changelog file? |
hey, @sky-joker what format needs to be followed for the changelog file? |
Hi @Anant99-sys Sorry, I should have provided how or sample. Official Document https://docs.ansible.com/ansible/latest/community/development_process.html#changelogs Please put in the changelog in the below path. The following is naming rule.
Please also see the following to the changelog contents. |
64b8031
to
b744e49
Compare
b744e49
to
43c9264
Compare
Hi @Anant99-sys I'm testing the new option if it works well now. ---
- name: Instant Clone Playbook
hosts: localhost
gather_facts: false
tasks:
- name: Make an instant clone
vmware_guest_instant_clone:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
datacenter: "{{ dc1 }}"
host: "{{ esxi1 }}"
folder: "{{ f1 }}"
parent_vm: test-inst-linux.homelab
name: test-linux
datastore: "{{ datastore }}"
guestinfo_vars:
- hostname: fuga
ipaddress: 192.168.10.226
netmask: 255.255.255.0
gateway: 192.168.10.1
dns: 192.168.0.1
networktype: static
uuid: 421afeb8-1559-384e-7b45-84a343496c6c
uuidHex: 421afeb8-1559-384e-7b45-84a343496c6c By the way, the instant clone was made well(didn't do customization). My environment parent_vm OS is RHEL8(vmware-toolsd and Perl installed) |
Can you check in the mob for vsphere client whether extra config parameters are instantiated? |
Thanks for your response. ---
- name: Instant Clone Playbook
hosts: localhost
gather_facts: false
tasks:
- name: Make an instant clone
vmware_guest_instant_clone:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
datacenter: "{{ dc1 }}"
host: "{{ esxi1 }}"
folder: "{{ f1 }}"
parent_vm: test-inst-linux.homelab
name: test-linux
datastore: "{{ datastore }}"
guestinfo_vars:
- hostname: test-linux
ipaddress: 192.168.10.226
netmask: 255.255.255.0
gateway: 192.168.10.1
dns: 192.168.0.1
networktype: static
uuid: 421afeb8-1559-384e-7b45-84a343496c6c
uuidHex: 421afeb8-1559-384e-7b45-84a343496c6c
- name: Gather vm info
vmware_guest_info:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: false
datacenter: "{{ dc1 }}"
name: test-linux
schema: vsphere
properties:
- config.extraConfig
register: gather_config_extra_result
- name: set the result variable
set_fact:
result: >-
{{ result | default([])
+ [{item.key:item.value}]
}}
loop: "{{ gather_config_extra_result.instance.config.extraConfig }}"
when:
- item.key | regex_search('guestinfo')
- debug: var=result $ ansible-playbook main.yml
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'
PLAY [Instant Clone Playbook] ******************************************************************************************************************************************************
TASK [Make an instant clone] *******************************************************************************************************************************************************
changed: [localhost]
TASK [Gather vm info] **************************************************************************************************************************************************************
ok: [localhost]
TASK [set the result variable] *****************************************************************************************************************************************************
(snip)
TASK [debug] ***********************************************************************************************************************************************************************
ok: [localhost] => {
"result": [
{
"guestinfo.vmtools.description": "open-vm-tools 11.0.5 build 15389592"
},
{
"guestinfo.vmtools.versionString": "11.0.5"
},
{
"guestinfo.vmtools.versionNumber": "11269"
},
{
"guestinfo.vmtools.buildNumber": "15389592"
},
{
"guestinfo.ic.hostname": "test-linux"
},
{
"guestinfo.ic.ipaddress": "192.168.10.226"
},
{
"guestinfo.ic.netmask": "255.255.255.0"
},
{
"guestinfo.ic.gateway": "192.168.10.1"
},
{
"guestinfo.ic.dns": "192.168.0.1"
},
{
"guestinfo.ic.networktype": "static"
},
{
"guestinfo.ic.uuid": "421afeb8-1559-384e-7b45-84a343496c6c"
},
{
"guestinfo.ic.uuidHex": "421afeb8-1559-384e-7b45-84a343496c6c"
}
]
}
(snip) I see that the extra parameters set to My Environment
|
Hey @sky-joker Let me try in my environment and I will let you know |
hey @sky-joker , |
Thanks, @Anant99-sys for looking for the method. |
I found out how to customize Guest OS in an instant clone vm. A customization operation will be failed if it doesn't install to a template.
The following code is a sample to customize in an instant clone vm. #!/usr/bin/env python
from pyVim.connect import SmartConnect, Disconnect
from pyVmomi import vim, vmodl
import ssl
import atexit
# Please change your environment
host = 'vcenter hostname or ip address'
username = '[email protected]'
password = 'vcenter user password'
mob = vim.VirtualMachine
# The variables need to do customization
vm_name = "test-linux" # name of the made an instant clone vm
guest_user = "root" # guest user name
guest_password = "guest user password"
if __name__ == "__main__":
context = None
if hasattr(ssl, '_create_unverified_context'):
context = ssl._create_unverified_context()
si = SmartConnect(host=host,
user=username,
pwd=password,
sslContext=context)
atexit.register(Disconnect, si)
content = si.content
mob_list = content.viewManager.CreateContainerView(content.rootFolder,
[mob],
True)
for mob in mob_list.view:
if mob.name == vm_name:
vm_obj = mob
if vm_obj:
# https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538cf2ec-b34f-4bae-a332-3820ef9e7773/vim.vm.GuestCustomizationManager.html
guest_custom_mng = content.guestCustomizationManager
# Make an object for authentication in a guest OS
# https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538cf2ec-b34f-4bae-a332-3820ef9e7773/vim.vm.guest.NamePasswordAuthentication.html
auth_obj = vim.vm.guest.NamePasswordAuthentication()
auth_obj.username = guest_user
auth_obj.password = guest_password
# Make a spec object to customize Guest OS
customization_spec = vim.vm.customization.Specification()
customization_spec.globalIPSettings = vim.vm.customization.GlobalIPSettings()
customization_spec.globalIPSettings.dnsServerList = ["10.1.1.1"]
# Make an identity object to do linux prep
# The params are reflected the specified following after rebooting OS
# https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538cf2ec-b34f-4bae-a332-3820ef9e7773/vim.vm.customization.LinuxPrep.html
customization_spec.identity = vim.vm.customization.LinuxPrep()
customization_spec.identity.domain = "example.com"
customization_spec.identity.hostName = vim.vm.customization.FixedName()
customization_spec.identity.hostName.name = "fugafuga"
customization_spec.nicSettingMap = []
adapter_mapping_obj = vim.vm.customization.AdapterMapping()
adapter_mapping_obj.adapter = vim.vm.customization.IPSettings()
adapter_mapping_obj.adapter.ip = vim.vm.customization.FixedIp()
adapter_mapping_obj.adapter.ip.ipAddress = "192.168.111.1"
adapter_mapping_obj.adapter.subnetMask = "255.255.255.0"
adapter_mapping_obj.adapter.gateway = ["192.168.111.254"]
customization_spec.nicSettingMap.append(adapter_mapping_obj)
# https://vdc-download.vmware.com/vmwb-repository/dcr-public/b50dcbbf-051d-4204-a3e7-e1b618c1e384/538cf2ec-b34f-4bae-a332-3820ef9e7773/vim.vm.GuestCustomizationManager.html#customize
r = guest_custom_mng.CustomizeGuest_Task(vm_obj, auth_obj, customization_spec)
print(r) About the customization, the vmware_guest module also has the function to make a customization spec, please also refer. community.vmware/plugins/modules/vmware_guest.py Lines 2261 to 2423 in 88662da
|
@sky-joker |
@Anant99-sys this PR contains the following merge commits: Please rebase your branch to remove these commits. |
786f922
to
969899a
Compare
recheck |
So this message is coming for the failing test : |
A virtual machine needs
So, I think that I haven't a problem also remove a virtual machine customization test. |
Also, could you please add the condition(a template must have |
OK I will add that |
So this will be taken care of by you? |
Yes. |
Ok cool 👍🏻 |
2843aaa
to
0ed60eb
Compare
tests/integration/targets/vmware_guest_instant_clone/tasks/main.yml
Outdated
Show resolved
Hide resolved
Error resolving Tox FIx Guestinfo Var changelog file added suggested changes changelog lines fix changelog lines fix CustomizationTask Added Whitespace removal TOX linters Guest Os condition FQCN
e5f3da4
to
ac3f429
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thanks @Anant99-sys!
SUMMARY
Adding GuestOS Customization feature for Instant Cloned VM
ISSUE TYPE
COMPONENT NAME
vmware_guest_instant_clone module
ADDITIONAL INFORMATION