本文介绍了ansible 有 yaml 编辑模块吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to modify a yaml file (schleuder configuration) and I'd like to do this from an ansible playbook - is there a module to do so? Hard to google for this, everything that turns up is how to write playbooks.

推荐答案

我也有配置管理 yaml 文件的需求.我写了一个 ansible 模块,它在编辑 yaml 文件时尝试是幂等的.

I also have the need to config manage yaml files. I have written an ansible module that attempts to be idempotent while editing yaml files.

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

I call it yedit (yaml-edit). https://github.com/kwoodson/ansible-role-yedit

如果您觉得有用,请告诉我.当我们的团队遇到需要时,我会通过请求或拉取请求添加功能.

Please let me know if you find it useful. I'll be adding features when our team runs into the need, by request, or by pull-request.

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

Here is a simple playbook example:

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

应该产生如下所示的内容:

Should produce something that looks like this:

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

2018 年 5 月 27 日

5/27/2018

这篇关于ansible 有 yaml 编辑模块吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 09:12