mitre.yedit
Ansible 模块:Yedit
这个仓库包含一个用于修改 YAML 文件的 Ansible 模块。
这个模块是为了在使用 yedit 时保存文件模式而进行的分支。
安装
您可以通过 Ansible Galaxy 安装 mitre.yedit
角色:
ansible-galaxy install mitre.yedit
如果您这样做,您还应该添加一个 requirements.yml
文件,以便其他使用您的剧本的用户知道需要安装哪些依赖:
# requirements.yml
roles:
- src: mitre.yedit
示例
管理 .yml
文件对于配置管理可能是必要的。这是您在 Ansible 剧本中使用 Yedit 模块的方法:
# playbook.yml
- hosts: localhost
roles:
- role: mitre.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 识别的角色目录中,以将其纳入您的 Ansible 设置中。有关将模块和插件嵌入角色中及使用模块实用程序的更多详细信息,请参考提供的 Ansible 文档链接:
文档
全面的文档可以在 GitHub 的角色库文件中直接找到。您可以通过 这里 访问它。