Provisioning VMWare hosts with Hammer

Just curious if anyone here has managed to fully provision a VMWare VM
using Hammer (selecting datastores, VM resources, etc)? If so, could you
share an example syntax?

Hi Josh,

I cannot give you the full details as my company doesn't allow that sort of
thing. But 1st cut of this loops around a CSV input file to create hosts
and allocate them to the correct ESX compute resource. We input OS version,
environment (Dev, UAT, Prod etc) the amount of CPU/RAM/Disk size.

It does some hammer commands to get some of the ID's etc from some more
basic inputs like OS version (6 or 7 and the media etc as most are held in
deterministic hostgroups - i.e. DEV-RHEL7) but the command that is run to
allocate hosts and then build them is:-

hammer --username "${SATUSER}" --password "${SATPWD}" host create
–name="${NAME}"
–organization-id=1
–location-id="${LOCATION_ID}"
–hostgroup-id="${HOSTGROUP_ID}"
–compute-resource-id="${COMPUTE_RESOURCE_ID}"
–compute-profile-id='4'
–environment-id="${ENVIRONMENT_ID}"
–managed=true
–partition-table-id=83
–medium-id="${MEDIUM_ID}"
–domain-id="${DOMAIN_ID}"
–root-pass='template'
–architecture="${ARCHITECTURE}"
–compute-resource="${COMPUTE_RESOURCE}"
–provision-method=build
–subnet-id="${SUBNET_ID}" \

–interface="identifier="eth0",primary=true,provision=true,managed=true,virtual=false,type="Nic::Managed",compute_type="${INTTYPE}",ip=${IP},subnet_id=${SUBNET_ID},compute_network="${ESXNETWORK}""
\

–compute-attributes="cluster="${ESXCLUSTER}",cpus=${CPUCOUNT},corespersocket=${CORECOUNT},path="${ESXPATH}",memory_mb=${MEMMB},guest_id=${GUEST_ID},start=1,hardware_version=vmx-10,scsi_controller_type="${SCSICTRL}",memoryHotAddEnabled=1,cpuHotAddEnabled=1"

–volume="datastore=${ESXDATASTORE},name='''Hard
disk''',size_gb=${DISKSIZE},thin=true,eager_zero=false"
–operatingsystem-id=${OSID}
–puppet-proxy-id=1
–puppet-ca-proxy-id=1
–owner-id="${SATUSERID}"
–build=true
–comment="Build via script on $(date)"
–ip="${IP}"

Hope this helps a little if you need more help I can expand as much as I
can.

Cheers
Paul

··· On Monday, 21 November 2016 18:54:45 UTC, Josh wrote: > > Just curious if anyone here has managed to fully provision a VMWare VM > using Hammer (selecting datastores, VM resources, etc)? If so, could you > share an example syntax? >

Hi Paul,

Thanks for the example. So, your script accepts input for things like OS
version/environment/CPU and then reads a CSV which contains things like the
hostname/IP/location/etc? Are you executing separate hammer commands to
retrieve the ID of some properties (like location, compute resource ID,
etc)?

If you could share a stripped down/minimalist version of your script, I
think everyone would really appreciate it.

Thanks!

Josh

··· On Mon, Nov 21, 2016 at 2:30 PM, Paul Seymour wrote:

Hi Josh,

I cannot give you the full details as my company doesn’t allow that sort
of thing. But 1st cut of this loops around a CSV input file to create hosts
and allocate them to the correct ESX compute resource. We input OS version,
environment (Dev, UAT, Prod etc) the amount of CPU/RAM/Disk size.

It does some hammer commands to get some of the ID’s etc from some more
basic inputs like OS version (6 or 7 and the media etc as most are held in
deterministic hostgroups - i.e. DEV-RHEL7) but the command that is run to
allocate hosts and then build them is:-

hammer --username “${SATUSER}” --password “${SATPWD}” host create
–name="${NAME}"
–organization-id=1
–location-id="${LOCATION_ID}"
–hostgroup-id="${HOSTGROUP_ID}"
–compute-resource-id="${COMPUTE_RESOURCE_ID}"
–compute-profile-id=‘4’
–environment-id="${ENVIRONMENT_ID}"
–managed=true
–partition-table-id=83
–medium-id="${MEDIUM_ID}"
–domain-id="${DOMAIN_ID}"
–root-pass=‘template’
–architecture="${ARCHITECTURE}"
–compute-resource="${COMPUTE_RESOURCE}"
–provision-method=build
–subnet-id="${SUBNET_ID}"
–interface=“identifier=“eth0”,primary=true,provision=
true,managed=true,virtual=false,type=“Nic::Managed”,
compute_type=”${INTTYPE}",ip=${IP},subnet_id=${SUBNET_
ID},compute_network="${ESXNETWORK}""
–compute-attributes=“cluster=”${ESXCLUSTER}",cpus=${
CPUCOUNT},corespersocket=${CORECOUNT},path="${ESXPATH}"
,memory_mb=${MEMMB},guest_id=${GUEST_ID},start=1,hardware_
version=vmx-10,scsi_controller_type="${SCSICTRL}",memoryHotAddEnabled=1,cpuHotAddEnabled=1"

–volume=“datastore=${ESXDATASTORE},name=’’‘Hard
disk’’’,size_gb=${DISKSIZE},thin=true,eager_zero=false”
–operatingsystem-id=${OSID}
–puppet-proxy-id=1
–puppet-ca-proxy-id=1
–owner-id="${SATUSERID}"
–build=true
–comment=“Build via script on $(date)”
–ip="${IP}"

Hope this helps a little if you need more help I can expand as much as I
can.

Cheers
Paul

On Monday, 21 November 2016 18:54:45 UTC, Josh wrote:

Just curious if anyone here has managed to fully provision a VMWare VM
using Hammer (selecting datastores, VM resources, etc)? If so, could you
share an example syntax?


You received this message because you are subscribed to the Google Groups
"Foreman users" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to foreman-users+unsubscribe@googlegroups.com.
To post to this group, send email to foreman-users@googlegroups.com.
Visit this group at https://groups.google.com/group/foreman-users.
For more options, visit https://groups.google.com/d/optout.

Hi,

The CSV is this:-

Hostname,OS Version,Location,Environment,Domain,Network Type,CPU Count,
Core Per CPU Count, Memory in MB,Disk Size in GB,Puppet Role

The script splits that up does some error handling (does the host already
exist etc), makes sure the inputs are valid for the Satellite server in
terms of location, domain, environment, subnet which can then derive the
hostgroup and not entering silly things for the amount of CPU/RAM etc.

it then has all the inputs to call the main hammer command to build the
thing.

It does do another call out to our Infoblox setup to get a static IP in a
network range (hence the network type in the CSV) and uses that.

It's not very elegant and I threw it together very fast as we had a few
hundred VM's to build next version will use a lot more automated way to
push the inputs (I want 3 new VM's -> go) but it's OK for now.

Will see if I can post it somewhere suitable.

Cheers
Paul