salt-cloud & setting hostname after salt is installed

887 views
Skip to first unread message

schlag ify

unread,
Oct 12, 2015, 1:22:52 PM10/12/15
to Salt-users
Hi,

I am new to salt-cloud, and finally have it successfully provisioning Linux vm's, however the resulting vm's still have the template's hostname.   Is there a recommended way of having salt-cloud set the hostname for a newly provisioned vm?  

thanks

schlag ify

unread,
Oct 13, 2015, 10:28:11 AM10/13/15
to Salt-users
The resulting debug output of salt-cloud suggests that the newly provisioned vm should have its `id` grain updated with the new hostname, but then when I ssh into the vm the hostname is not available via grains (using 'salt-call grains.get id', nor does it show up in 'salt-call grains.items'), or anywhere on the system.   The vm retains the original hostname of the template, and no salt states can update the hostname if it's unavailable.

I have vmware tools installed, and have verified that it is running.   Any ideas??

Robert Booth

unread,
Oct 14, 2015, 9:26:43 AM10/14/15
to Salt-users
How I understand things working with salt-cloud is that the name you specify when executing salt-cloud will be used for the salt id on the new node. This will not update the local hostname.

(Following hasn't been tested yet. I'll try to test it today)
I would suggest creating a state file to update the hostname of the node to the minion id.
Put in your salt-cloud profile to run this state after it installs.
example.

Cloud profile file
ubuntubox:
  ...
  minion:
    startup_states: sls
    sls_list:
      - updatehostname



updatehostname.sls
"Update my name {{ grains['id'] }}":
  network.system:
    - name: {{ grains['id'] }}
    - enabled: True
    - hostname: {{ grains['id'] }}
    - apply_hostname: True



Hope this is what you were looking for.

schlag ify

unread,
Oct 14, 2015, 3:35:55 PM10/14/15
to Salt-users
thank you for your suggestions.   it turned out that i had an /etc/salt/minion file in place on my template from an older saltstack installation and the bootstrap script wasn't overwriting it.   your tips about startup_states and updatehostname.sls helped me get alot further.   much appreciated!
Reply all
Reply to author
Forward
0 new messages