Created
April 4, 2019 16:05
-
-
Save fl64/0f3ad9a4ccc0215cc661ca4d613c5745 to your computer and use it in GitHub Desktop.
Ansible playbook for modifying /etc/docker/daemon.json config (based on https://stackoverflow.com/questions/50796341/add-a-new-key-value-to-a-json-file-using-ansible)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: all | |
become: yes | |
gather_facts: false | |
vars: | |
tasks: | |
- name: Check that the /etc/docker/daemon.json exists | |
stat: | |
path: /etc/docker/daemon.json | |
register: stat_result | |
- block: | |
- name: load var from file | |
slurp: | |
src: /etc/docker/daemon.json | |
register: docker_vars | |
- debug: | |
msg: "{{ docker_vars.content|b64decode|from_json }}" | |
- name: append more key/values | |
set_fact: | |
docker_vars: "{{ docker_vars.content|b64decode|from_json }}" | |
- name: append more key/values | |
set_fact: | |
docker_vars: "{{ docker_vars | default([]) | combine({ item.key : item.value }) }}" | |
with_items: | |
- { key: "log-driver", value: "journald" } | |
- { key: "registry-mirrors", value: [ "http://registry.dev.local" ] } | |
- debug: | |
var: docker_vars | |
- name: write var to file | |
copy: | |
content: "{{ docker_vars | to_nice_json }}" | |
dest: /etc/docker/daemon.json | |
when: stat_result.stat.exists == true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment