Run a default script soon after Instance creation?

asked 2017-03-30 00:23:20 -0600

ShubhamMeshram gravatar image

updated 2017-03-30 00:38:09 -0600

If I launch an instance for the first time, I want to run a small script of commands in it.

For example if I need to change the hostname of the VM or want it to display the output of ifconfig when it starts up or any command or script for that matter.

How can I do this?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-03-30 00:42:55 -0600

Most likely, your instance has cloudinit built-in. You can put your script in a file, ensure it starts with #!/bin/bash, then submit it like this openstack server create --user-data YOUR-SCRIPT-FILE .... I can recommend a very nice presentation on cloudinit held at the Tokyo summit in October 2015.

edit flag offensive delete link more


openstack server create --image cirros-0.3.5-x86_64-uec --flavor m1.tiny MyFirstInstance

if that is the command to create an instance should I append --user-data YOUR-SCRIPT-FILE to the end of the command?

ShubhamMeshram gravatar imageShubhamMeshram ( 2017-03-30 00:47:13 -0600 )edit

I think it needs to come before the instance name, but why don't you look up the documentation?

Bernd Bausch gravatar imageBernd Bausch ( 2017-03-30 01:03:25 -0600 )edit

I didn't really find a solution to my question in the link you provided. Please help me do this

ShubhamMeshram gravatar imageShubhamMeshram ( 2017-04-03 00:12:02 -0600 )edit

In your answer, what do you mean by --user-data?

ShubhamMeshram gravatar imageShubhamMeshram ( 2017-04-03 00:12:48 -0600 )edit

Did you watch the video? What is it that you don't understand?

--user-data is a parameter to the openstack server create command.

Bernd Bausch gravatar imageBernd Bausch ( 2017-04-03 00:35:24 -0600 )edit

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower


Asked: 2017-03-30 00:23:20 -0600

Seen: 663 times

Last updated: Mar 30 '17