简体   繁体   中英

Upload bash script to Ubuntu machine deploymed by MAAS

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!

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.

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM