【问题标题】:Upload bash script to Ubuntu machine deploymed by MAAS将 bash 脚本上传到 MAAS 部署的 Ubuntu 机器上
【发布时间】:2021-09-05 23:33:57
【问题描述】:

信息+目标:

我正在使用 MAAS 通过 Ubuntu 部署工作站。

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

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

 


 

我做了什么 + 错误:

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

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 将其上传到服务器,然后执行它?如果没有,是否可以修复我遇到的错误?

先谢谢了!

【问题讨论】:

  • 我不知道maas,但是从错误信息中可以看出,它把run_script参数的内容当成一个命令。我的猜测是您必须编写类似run_script: [/bin/bash /root/script.sh] 的内容,但在执行此操作之前请检查 maas 文档。
  • 感谢您的回复。您是说问题可能是它不需要引号 (") 吗?
  • 正如我所说,我不知道 maas,但如果我要设计这样的界面,我会要求方括号之间是您要输入的内容一个 bash shell,您不会以这种方式键入带引号的命令,对吗?但首先,阅读文档。比猜测要好。

标签: linux bash ubuntu deployment maas


【解决方案1】:

这可以执行命令:

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

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2016-12-15
      • 1970-01-01
      • 2015-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-29
      • 1970-01-01
      相关资源
      最近更新 更多