1

信息+目标:

我正在使用 MAAS 来部署带有 Ubuntu 的工作站。

MAAS 只是用股票 Ubuntu 部署机器,然后我运行我编写的 bash 脚本来设置所需的一切。

到目前为止,我已经在新部署的机器上手动运行了该 bash 脚本。现在,我正在尝试让 MAAS 自动运行该脚本。

 


 

我做了什么+错误:

在 MAAS 机器中,我创建了以下名为 curtin 的文件/var/snap/maas/current/preseeds/curtin_userdata_ubuntu,其中包含以下内容:

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"]

但是,在日志中,我看到以下内容:

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'

 


 

问题

我不确定将这么大的 bash 脚本放在 curtin 文件中是个好主意。有没有办法将 bash 脚本存储在 MAAS 机器上,并让 curtin 将其上传到服务器,然后执行它?如果没有,是否可以修复我遇到的错误?

提前谢谢!

4

2 回答 2

0

我没有将我的脚本添加到 curtin 文件中。我在命令下运行并部署服务器。

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

于 2022-01-18T14:08:48.060 回答
0

这有效地执行了命令:

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

虽然这种方法仍然意味着我必须写入文件然后执行它。我仍然希望有一种方法可以上传文件然后执行它。

于 2021-06-23T09:19:46.740 回答