简体   繁体   English

cloud-init runcmd(使用 MAAS)

[英]cloud-init runcmd (using MAAS)

I'm unable to run bash scripts in "runcmd:" that aren't inline.我无法在非内联的“runcmd:”中运行 bash 脚本。

runcmd:
    - [ bash, -c, echo "=========hello world=========" >>foo1.bar ]
    - [ bash, -c, echo "=========hello world=========" >>foo2.bar ]
    - [ bash, -c, /usr/local/bin/foo.sh ]

The first two lines are successfully run on the deployed Ubuntu instance.前两行在部署的 Ubuntu 实例上成功运行。 However, the foo.sh doesn't seem to run.但是, foo.sh 似乎没有运行。

Here is /usr/local/bin/foo.sh:这是/usr/local/bin/foo.sh:

#!/bin/bash
echo "=========hello world=========" >>foosh.bar

foo.sh has executable permissions for root and resides on the MAAS server. foo.sh 具有 root 的可执行权限并驻留在 MAAS 服务器上。

I've looked at the following but they don't seem to sort out my issue:我查看了以下内容,但他们似乎没有解决我的问题:

Any help or tips would be greatly appreciated.任何帮助或提示将不胜感激。

Anything you run using runcmd must already exist on the filesystem.您使用runcmd运行的任何内容都必须已经存在于文件系统中。 There is no provision for automatically fetching something from a remote host.没有从远程主机自动获取某些东西的规定。

You have several options for getting files there.您有几个选项可以在那里获取文件。 Two that come to mind immediately are:立即想到的两个是:

  • You could embed the script in your cloud-init configuration using the write-files directive :您可以使用write-files指令将脚本嵌入到 cloud-init 配置中:

     write_files: - path: /usr/local/bin/foo.sh permissions: '0755' content: | #./bin/bash echo "=========hello world=========" >>foosh:bar runcmd, - [bash. /usr/local/bin/foo.sh]
  • You could fetch the script from a remote location using curl (or similar tool):您可以使用curl (或类似工具)从远程位置获取脚本:

     runcmd: - [curl, -o, /usr/local/bin/foo.sh, http://somewhere.example.com/foo.sh] - [bash, /usr/local/bin/foo.sh]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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