【问题标题】:Cloud-init runcmd syntx of a command that adding a line to file将行添加到文件的命令的 Cloud-init runcmd 语法
【发布时间】:2019-05-13 22:23:45
【问题描述】:

我正在尝试执行这个简单的命令,但它一直失败:

 echo "secret_backend_command: /home/ec2-user/dd-get-secrets.py" >> /etc/datadog-agent/datadog.yaml"

我尝试了以下所有方法:

        - [ sh, -c, echo "secret_backend_command: /home/ec2-user/dd-get-secrets.py" >> /etc/datadog-agent/datadog.yaml ]

        - 'sh -c "echo \"secret_backend_command: /home/ec2-user/dd-get-secrets.py\" >> /etc/datadog-agent/datadog.yaml"'

        - sh -c "echo 'secret_backend_command: /home/ec2-user/dd-get-secrets.py' >> /etc/datadog-agent/datadog.yaml

知道如何修复这个引号吗?

注意我用另一个文件而不是 datadpg.yaml 进行测试,因为我是 获得此权限被拒绝。

我在 here 中找到的示例不起作用

【问题讨论】:

    标签: amazon-web-services amazon-ec2 user-data cloud-init


    【解决方案1】:

    我改变了执行它的方式,而不是将它放在 runcmds 的 yaml 列表中,我创建了一个脚本,而是将此命令放入其中并在 runcmds 中调用脚本。通过这样做,我摆脱了 cloud-init 中“:”和引号的棘手处理。

      UserData:
        'Fn::Base64': !Sub |
          #cloud-config
          write_files:
            - path: /home/ec2-user/update-datadog-config.sh
              permissions: 0744
              owner: root
              content: |
                #!/usr/bin/env bash
                set -e
                echo "secret_backend_command: /home/ec2-user/dd-get-secrets.py" >> /etc/datadog-agent/datadog.yaml
          runcmd:
            - bash /home/ec2-user/update-datadog-config.sh
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 2011-03-10
      • 2012-05-22
      • 2022-08-15
      • 2021-05-12
      • 2019-03-25
      相关资源
      最近更新 更多