Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a yaml editing module for ansible?

Tags:

ansible

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.

like image 510
chichak Avatar asked Oct 07 '15 13:10

chichak


People also ask

Does Ansible use Yml?

Ansible uses YAML syntax for expressing Ansible playbooks. This chapter provides an overview of YAML. Ansible uses YAML because it is very easy for humans to understand, read and write when compared to other data formats like XML and JSON.

Does Ansible use YAML or JSON?

This page provides a basic overview of correct YAML syntax, which is how Ansible playbooks (our configuration management language) are expressed. We use YAML because it is easier for humans to read and write than other common data formats like XML or JSON.


1 Answers

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.

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 

Edit: 5/27/2018

like image 146
kwoodson Avatar answered Sep 23 '22 05:09

kwoodson