是否有ansible的yaml编辑模块?

问题描述 投票:19回答:3

我需要修改一个yaml文件(schleuder configuration),我想从一个ansible playbook中做到这一点 - 是否有一个模块可以这样做?很难谷歌这一点,所有出现的是如何写剧本。

ansible
3个回答
20
投票

我还需要配置管理yaml文件。我编写了一个ansible模块,在编辑yaml文件时尝试是幂等的。

我称之为yedit(yaml-edit)。 https://github.com/kwoodson/ansible-role-yedit

如果您觉得有用,请告诉我。当我们的团队满足需求,请求或拉取请求时,我将添加功能。

这是一个简单的剧本示例:

roles:
- lib_yaml_editor

tasks:
- name: edit some yaml
  yedit:
    src: /path/to/yaml/file
    key: foo
    value: bar

- name: more complex data structure
  yedit:
    src: /path/to/yaml/file
    key: a#b#c#d
    value:
      e:
        f:  This is a test

应该产生这样的东西:

foo: bar
a:
  b:
    c:
      d:
        e:
          f: This is a test

编辑:5/27/2018


1
投票

没有这样的模块。你可以通过查看https://docs.ansible.com/ansible/list_of_all_modules.html来查看

你最好的选择是使用lineinfiletemplatecopy模块。


© www.soinside.com 2019 - 2024. All rights reserved.