【问题标题】:Ansible. Insert block of text FROM file to the file可靠的。将文本块从文件插入到文件中
【发布时间】:2023-02-10 20:05:00
【问题描述】:

我知道有 ansible.builtin.blockinfile 存在。我可以用它在文件中插入一段文本,但文本应该作为任务中的“块”提供。是否可以使用文件作为“块”的来源? IE。:

- name: create/update somefile.config
  ansible.builtin.blockinfile:
    path: /home/user/something/configuration.yaml
    insertbefore: "someline:"
    block: something/configuration.yaml

something/configuration.yaml 是一个文件

【问题讨论】:

  • 看来你明白你可以“插入一段文字”.你想从文件中插入一些东西配置.yaml.该文件的内容似乎是 YAML。 YAML 应该如何格式化为文本?发布文件的内容和预期的文本块。参见minimal reproducible example

标签: ansible ansible-2.x


【解决方案1】:

我的解决方案

- name: create/update somefile.config
  ansible.builtin.blockinfile:
    path: /home/user/something/configuration.yaml
    insertbefore: "someline:"
    block: "{{ item }}"
  with_items:
    - "{{lookup('ansible.builtin.file', 'something/configuration.yaml') }}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-28
    • 2011-04-16
    • 1970-01-01
    • 2023-02-10
    • 2020-06-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多