Skip to content

Instantly share code, notes, and snippets.

@goffinet
Forked from Akasurde/main.yml
Created December 23, 2020 19:08
Show Gist options
  • Save goffinet/036ee217b32228d2545522db5149ca84 to your computer and use it in GitHub Desktop.
Save goffinet/036ee217b32228d2545522db5149ca84 to your computer and use it in GitHub Desktop.
Automate CentOS 7 installation using Kickstart and vmware_guest module
---
- hosts: localhost
gather_facts: no
vars_files:
- vcenter_vars.yml
vars:
hostname: kickstart_vm
tasks:
- name: Boot VM with CentOS 7 installation iso in CDROM
vmware_guest:
validate_certs: False
hostname: '{{ vcenter_hostname }}'
username: '{{ vcenter_username }}'
password: '{{ vcenter_password }}'
datacenter: "{{ dc1 }}"
state: poweredon
cluster: Asia-Cluster1
disk:
- size_gb: 10
type: thin
datastore: ds_171_2
cdrom:
- controller_number: 0
unit_number: 0
state: present
type: iso
iso_path: "[ds_171_2] isos/CentOS-7.0-1406-x86_64-DVD.iso"
hardware:
memory_mb: 2048
num_cpus: 2
num_cpu_cores_per_socket: 2
name: "{{ hostname }}"
folder: /Asia-Datacenter1/vm/prod
guest_id: centos7_64Guest
networks:
- name: "privatepg"
- name: Handle boot parameter
vmware_guest_sendkey:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: "{{ hostname }}"
keys_send:
- ESC
- ESC
string_send: 'vmlinuz initrd=initrd.img inst.ks=http://{{ httpd_ip }}:{{ httpd_port }}/{{ kickstart_file }}'
delegate_to: localhost
vars:
kickstart_file: kickstart.cfg
httpd_ip: 192.168.10.1
httpd_port: 9000
- name: Start installation after providing boot parameter at installation prompt
vmware_guest_sendkey:
validate_certs: False
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
name: "{{ hostname }}"
keys_send:
- ENTER
delegate_to: localhost
# Rest of your playbook
vcenter_hostname: 10.65.201.19
vcenter_username: administrator@vsphere.local
vcenter_password: Esxi@123$%7
dc1: Asia-Datacenter1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment