Rheinwerk.yedit
// vim: ft=asciidoc
= yedit 仓库 :toc: macro :toc-title:
toc::[]
== Ansible 角色: Yedit
这个仓库包含一个用于修改 yaml 文件的 ansible 模块。
我没有找到一个好的方法来通过 ansible 编辑 yaml 文件和进行配置管理。这是我的尝试。
== 安装
你可以通过 Ansible Galaxy 安装:
$ ansible-galaxy install kwoodson.yedit
如果这样做,您还应该添加一个 requirements.yml
,以便其他用户知道要安装哪些依赖项:
---
- src: kwoodson.yedit
然后你可以在剧本中通过在使用之前导入它来引用:
roles:
- kwoodson.yedit
- 使用 yedit 的角色
== 示例
有时需要对 .yml 文件进行配置管理。 [source,yaml]
- hosts: localhost
gather_facts: no
roles:
kwoodson.yedit tasks:
name: 管理 yaml 文件 yedit: src: /tmp/test.yaml key: a.b.c value: d: e: f: 这是一个测试
name: 获取特定值 yedit: src: /tmp/test.yaml state: list key: a.b.c.d.e.f register: yeditout
debug: var=yeditout
== 开发
作为一个角色,只需将其复制到 Ansible 识别的任何角色目录中。有关详细信息,请参见 http://docs.ansible.com/ansible/latest/index.html[Ansible 文档]:
- http://docs.ansible.com/ansible/devel/playbooks_reuse_roles.html#embedding-modules-and-plugins-in-roles[在角色中嵌入模块和插件]
- http://docs.ansible.com/ansible/latest/intro_configuration.html#module-utils[module_utils]
== 文档
完整的文档可以在这里 https://github.com/kwoodson/ansible-role-yedit/blob/master/library/yedit.py#L15[查看]。