I’m trying to manage yaml with yq
and ansible
Here is my tasks. It will output the yaml “final.yaml” I want to manage
- name: Sync Encrypt Yaml To My Remote Server
hosts: all
gather_facts: false
tasks:
- name: Format config yaml using yq at local
ansible.builtin.shell:
cmd: |
set -o pipefail
yq '(.. | select(has("file"))) |= load("./" + .file)' main.yaml > ./final.yaml
register: format_result
delegate_to: localhost
changed_when: format_result.rc != 0
- name: Upload Config Value To Remote Server
ansible.builtin.copy:
src: "./final.yaml"
dest: "/tmp/remote.yaml"
mode: "0644"
diff: true
I want to manage these files separately. and my main.yaml like below.
app:
name: my-app
db: # my database config
file: ./db.yaml
cache: # my cache config
file: ./cache.yaml
It can successfully output the final.yaml. However, it fails after I encrypt the yaml with ansible-vault
.
Any ideas on how to solve this?