16.04:如何从 cloud-init 编写和运行 bash shell 脚本?

16.04:如何从 cloud-init 编写和运行 bash shell 脚本?

我正在编写以下 cloud-init 文件,该文件将在 OpenStack 中部署 VM 时执行:

#cloud-config
password: passwword
chpasswd: { expire: False }
ssh_pwauth: True

write_files:
-   content: |
        This is the write_files and should be line 1 of 2

    path: /home/ubuntu/file.txt

-   content: |
        echo "This is the runcmd and should be line 3 of 3" >> /home/ubuntu/file.txt

    owner: root:root
    permissions: '755'
    path: /home/ubuntu/bin/test

runcmd:
  - echo "This is the runcmd and should be line 2 of 2" >> /home/ubuntu/file.txt
  - test

VM启动后,输出为cat file.txt

This is the write_files and should be line 1 of 2
This is the runcmd and should be line 2 of 2 

cloud-init因此,不会执行运行名为 的 shell 脚本的最后一行,test该脚本会写入file.txt..

我究竟做错了什么 ?!

答案1

我猜这/home/ubuntu/bin/不在 PATH 中。尝试/home/ubuntu/bin/testruncmd

相关内容