Run script post installation


Can someone help me to run a script after Ubuntu installation with MAAS, i would like to include the script installation like part of Ubuntu installation, i did some research and found that i have to do:
maas user machine deploy $SYSTEM_ID user_data=<base-64-encoded-script>
But when i run this command i get the error:
argument COMMAND: invalid choice: 'user' (choose from 'login', 'logout', 'list', 'refresh', 'init', 'apikey', 'configauth', 'createadmin', 'changepassword')



That’s the correct way of running a script after the installation.

It looks like you haven’t configured your API client, though. You can use maas list to see which endpoints the API client already knows about.

If you haven’t done so already, you need to login first:

maas login user <your-maas-url> <your-maas-api-key>

Hi @bjornt and thank you for the reply,
You have right, i wasn’t logged to the API, now i can login to the API and i did:
1- Created a script:
echo === $date ===
ssh-import-id user
) | tee /ssh-key-import.log

2- Give execution permission:
#chmod +x

3- Convert script to base64:
#tmp=$(base64 ./
4- Customize the node deployment:
maas user machine deploy Node-1 user_data=$tmp
But it gives this error:
maas root machine deploy Node-1 user_data=$tmp
‘cgopIHwgdGVlIC9zc2gta2V5LWltcG9ydC5sb2cK’ is not a name=value or name@=filename pair

Can you help please!

I changed my script to:
apt-get update -y
apt-get install vlan -y

And now it’s working.

FWIW, we simply forward the data to cloud-init, so any of the supported cloud-init userdata formats should be supported:

There’s no need to make the script executable, since it’s passed as a text string.

The error you see is because the base64 command will introduce line breaks. To make it work with longer scripts you need to pass -w 0 to it in order to disable the line breaks.

A better solution is to let the MAAS CLI read the file directly:

maas root machine deploy Node-1

Hi bjornt and andreserl,

Thank you for the quick reply, i’m passed the script directly touser_data@=/opt/ and it work in this case:
apt-get -y update
apt-get -y install vlan

mkdir /tmp/TMP
cd /tmp/TMP
wget -P /tmp/TMP

The deploy command accepts the script but after he installation i don’t find /TMP folder and impmitool package , i added sudo before each command but without success.


Solved in this topic Script to user_data not working