Hi Tony,
There are two ways of adding an esxi host to vCenter:
- In standalone mode (not part of a vCenter cluster)
- Part of a vCenter cluster
See the following examples:
In standalone mode, first you'll need a host folder to place your esxi
hosts. Bear in mind here that *vcenter_folder* should be in the following
form: /datacenter_name/host/name. For example if your dc is DC01:
/DC01/host/myhostfolder.
- name: Create a host folder
vcenter_folder:
hostname: "{{ hostvars[inventory_hostname]['vcenter'] }}"
username: "{{ vcenter_username | d(ansible_ssh_user) }}"
password: "{{ vcenter_password | d(ansible_ssh_pass) }}"
datacenter_name: "{{ datacenter_name }}"
folder_name: "{{ vcenter_folder }}"
folder_type: host
state: present
validate_certs: False
register: folder_result
delegate_to: localhost
run_once: True
retries: 10
until: folder_result is succeeded
- name: Add host to vCenter (standalone)
vmware_host:
hostname: "{{ hostvars[inventory_hostname]['vcenter'] }}"
username: "{{ vcenter_username | d(ansible_ssh_user) }}"
password: "{{ vcenter_password | d(ansible_ssh_pass) }}"
datacenter_name: "{{ datacenter_name }}"
folder: "{{ vcenter_folder }}"
esxi_hostname: "{{ hostvars[inventory_hostname]['fqdn'] }}"
esxi_username: "{{ esxi_admin_username | d('root') }}"
esxi_password: "{{ esxi_root_password | d('password') }}"
state: present
validate_certs: False
delegate_to: localhost
register: host_result
retries: 10
until: host_result is succeeded
Next option is to add a esxi host into an existing cluster:
- name: Attach esxi host to vCenter cluster
vmware_host:
hostname: "{{ hostvars[inventory_hostname]['vcenter'] }}"
username: "{{ vcenter_username | d(ansible_ssh_user) }}"
password: "{{ vcenter_password | d(ansible_ssh_pass) }}"
datacenter_name: "{{ datacenter_name }}"
cluster_name: "{{ cluster_name }}"
esxi_hostname: "{{ hostvars[inventory_hostname]['fqdn'] }}"
esxi_username: "{{ esxi_admin_username | d('root') }}"
esxi_password: "{{ esxi_root_password | d('password') }}"
state: present
validate_certs: False
delegate_to: localhost
Hope it helps,
Regards
--
Jorge Rua
El lun., 13 abr. 2020 a las 17:35, David Foley (<[email protected]>)
escribió:
> Hi Tony,
>
> Looking at the Documentation
> https://docs.ansible.com/ansible/latest/modules/vmware_host_module.html
>
> - name: Add ESXi Host to vCenter
> vmware_host:
> hostname: '{{ vcenter_hostname }}'
> username: '{{ vcenter_username }}'
> password: '{{ vcenter_password }}'
> datacenter: datacenter_name
> cluster: cluster_name
> esxi_hostname: '{{ esxi_hostname }}'
> esxi_username: '{{ esxi_username }}'
> esxi_password: '{{ esxi_password }}'
> state: present
> delegate_to: localhost
>
> This code will add the host to a Cluster,
>
>
> On Monday, April 13, 2020 at 4:48:40 PM UTC+1, Tony Wong wrote:
>>
>> I am new to ansible and want to know how to add a esxi host to vcenter in
>> a datacenter
>>
>> I have the following in a yml file but not sure what else to do
>>
>>
>> - hosts: localhost
>> connection: local
>> tasks:
>> - name: include vars
>> include_vars:
>>
>> - name: Add ESXi Host to vCenter
>> vmware_host:
>> hostname: '{{ vcenter_hostname }}'
>> username: '{{ vcenter_username }}'
>> password: '{{ vcenter_password }}'
>> datacenter: datacenter_name
>> esxi_hostname: '{{ esxi_hostname }}'
>> esxi_username: '{{ esxi_username }}'
>> esxi_password: '{{ esxi_password }}'
>> state: present
>> delegate_to: localhost
>> ~
>>
>>
>>
>>
>> please help as vmware ansible seems very limited in info
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7d76788c-cc3f-4530-80cd-626b4700cf1c%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7d76788c-cc3f-4530-80cd-626b4700cf1c%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
You received this message because you are subscribed to the Google Groups
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/CAFtje5O75ezCDVm0eM5QX3WKd-r6ujGzd9k_v4Qd898auLrznQ%40mail.gmail.com.