Run script post installation


#1

Hello,

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')

Thanks,


#2

Hi!

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>


#3

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 test.sh script:
#vi test.sh
#!/bin/bash
(
echo === $date ===
ssh-import-id user
) | tee /ssh-key-import.log

2- Give execution permission:
#chmod +x test.sh

3- Convert script to base64:
#tmp=$(base64 ./test.sh)
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!


#4

I changed my script to:
#!/bin/bash
apt-get update -y
apt-get install vlan -y

And now it’s working.


#5

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

https://cloudinit.readthedocs.io/en/latest/topics/format.html


#6

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 user_data@=test.sh


#7

Hi bjornt and andreserl,

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

But
mkdir /tmp/TMP
cd /tmp/TMP
wget http://mirrors.kernel.org/ubuntu/pool/universe/i/ipmitool/ipmitool_1.8.18-5build1_amd64.deb -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.

Thanks,


#8

When I was trying to install itunes on windows 7 it was not installing at all and literally crashing the system every time. Please help me to fix the problem so that I can work with the system.