1

Info + objective:

I'm using MAAS to deploy workstations with Ubuntu.

MAAS just deploys the machine with stock Ubuntu, and I then run a bash script I wrote to set up everything needed.

So far, I've ran that bash script manually on the newly deployed machines. Now, I'm trying to have MAAS run that script automatically.

 


 

What I did + error:

In the MAAS machine, I create the following file curtin file called /var/snap/maas/current/preseeds/curtin_userdata_ubuntu which contains the following:

write_files:
  bash_script:
    path: /root/script.sh
    content: |
      #!/bin/bash
      echo blabla
      ... very long bash script
    permissions: '0755'

late_commands:
  run_script: ["/bin/bash /root/script.sh"]

However, in the log, I see the following:

known-caiman cloud-init[1372]: Command: ['/bin/bash /root/script.sh']
known-caiman cloud-init[1372]: Exit code: -
known-caiman cloud-init[1372]: Reason: [Errno 2] No such file or directory: '/bin/bash /root/script.sh': '/bin/bash /root/script.sh'

 


 

Question

I'm not sure putting such a large bash script in the curtin file is a good idea. Is there a way to store the bash script on the MAAS machine, and have curtin upload it to the server, and then execute it? If not, Is it possible to fix the error I'm having?

Thanks ahead!

jessefournier
  • 181
  • 1
  • 2
  • 13
  • I don't know _maas_, but from the error message, it is clear that it takes the content of the `run_script` parameter as a single command. My guess is that you would have to write something like `run_script: [/bin/bash /root/script.sh]`, but check the maas-documentation before you do this. – user1934428 Jun 22 '21 at 11:43
  • Thanks for the response. Are you saying the issue might be that it doesn't need the quotation marks (`"`) ? – jessefournier Jun 22 '21 at 12:20
  • As I said, I don't know _maas_, but if I would design an interface like this, I would request that between the square brackets comes what you would type into a bash shell, and you would not type the command with the quotes in that way, would you? But first of all, read the docs. Bettter than just guessing. – user1934428 Jun 22 '21 at 14:26

3 Answers3

0

This worked executing the command:

["curtin", "in-target", "--", "/bin/bash", "/root/script.sh"]

Though this method still means I have to write to a file and then execute it. I'm still hoping there's a way to upload a file and then execute it.

jessefournier
  • 181
  • 1
  • 2
  • 13
0

I do not add my script to curtin file. I run below command and deploy servers.

maas admin machine deploy $system_id user_data=$(base64 -w0 /root/script.sh)

0

I would try

runcmd:
   - [/bin/scp, user@host:/somewhere/script.sh, /root/]


late_commands:
  run_script: ['/bin/bash', '/root/script.sh']

This obviously imply that you inject the proper credentials on the machine being deployed.

Mandrappa
  • 31
  • 5