ansible - 是否可以将文件内容包含在剧本中?

标签 ansible

我需要在远程主机上创建或覆盖文件。模块 lineinfileblockinfile 在更新文件时很有用,但不能从头开始创建文件或完全覆盖现有文件。

显而易见的解决方案是使用copy,但我希望拥有尽可能多的独立剧本,而不需要附带文件。 是否可以将要创建的文件的内容包含在剧本中?

也许有一个带有文件内容的变量,可以用作copysrc=参数(我尝试过这个,但它确实无法工作,因为 src 需要本地文件)

最佳答案

复制内容:

  tasks:
    - copy:
        content: |
                 This is some
                 not too complex
                 cotent for a file
        dest: content.txt

但根据 Ansible doc :

This is for simple values, for anything complex or with formatting please switch to the template module.

关于ansible - 是否可以将文件内容包含在剧本中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38479423/

相关文章:

json - 检查 JSON 中除条件中提到的对象之外的对象

ansible - 在 Ansible 中注册和使用多个变量

deployment - 如何在 Ansible 中跳过角色执行

ssh - 通过 ssh 运行 Ansible 单个命令

python - 在 RedHat/CentOS 7 上使用 Python3 实现 Ansible(python3-dnf 问题)

kubernetes - Ansible 错误 : "[Errno 2] No such file or directory"

amazon-web-services - 用于将 IAM 角色附加到现有 EC2 实例的 Ansible 模块

docker - 使用 Ansible 在 Docker 容器内运行命令

ansible - 在ansible中用lineinfile换行

mysql - 如何使用 Ansible 为 MySQL/MariaDB root 用户设置并保存随 secret 码?