{"id":2137,"date":"2024-04-01T18:24:46","date_gmt":"2024-04-01T09:24:46","guid":{"rendered":"https:\/\/www.kwonline.org\/memo2\/?p=2137"},"modified":"2024-04-01T18:24:46","modified_gmt":"2024-04-01T09:24:46","slug":"ansible-to-modify-docker-daemon-json-file","status":"publish","type":"post","link":"https:\/\/www.kwonline.org\/memo2\/2024\/04\/01\/ansible-to-modify-docker-daemon-json-file\/","title":{"rendered":"Ansible \u3067 docker daemon.json \u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u3092\u7de8\u96c6\u3059\u308b"},"content":{"rendered":"<p>&nbsp;<br \/>\nAnsible \u3067 \/etc\/docker\/daemon.json \u30d5\u30a1\u30a4\u30eb\u3092\u3044\u3058\u3063\u305f\u306e\u3067\u30e1\u30e2\u3002<br \/>\nslurp moduel \u3092\u4f7f\u3063\u3066 JSON \u30d5\u30a1\u30a4\u30eb\u3092\u66f8\u304d\u63db\u3048\u305f\u3002<\/p>\n<p>\u307e\u305a\u306f ansible \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb (Ubuntu 22.04)<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\npip install ansible-core\r\nansible-galaxy collection install community.general\r\n<\/pre>\n<p>\u3064\u3065\u3044\u3066 playbook \u3092\u4f5c\u6210\u3002<br \/>\nupdate_daemon_json.yaml \u306e\u540d\u524d\u3067\u4fdd\u5b58\u3002<\/p>\n<pre class=\"brush: yaml; title: ; notranslate\" title=\"\">\r\n---\r\n- name: Update Docker daemon.json and restart Docker\r\n  hosts: localhost\r\n  become: true\r\n  vars:\r\n    log_config:\r\n      log-driver: json-file\r\n      log-opts:\r\n        max-size: &quot;10m&quot;\r\n        max-file: &quot;3&quot;\r\n  tasks:\r\n    - name: Read existing Docker daemon configuration\r\n      ansible.builtin.slurp:\r\n        src: \/etc\/docker\/daemon.json\r\n      register: daemon_config\r\n\r\n    - name: Decode the Docker daemon configuration\r\n      set_fact:\r\n        current_config: &quot;{{ daemon_config&#x5B;'content'] | b64decode | from_json }}&quot;\r\n\r\n    - name: Update the Docker daemon configuration\r\n      set_fact:\r\n        new_config: &quot;{{ current_config | combine(log_config, recursive=True) }}&quot;\r\n\r\n    - name: Write the updated configuration back to daemon.json\r\n      copy:\r\n        dest: \/etc\/docker\/daemon.json\r\n        content: &quot;{{ new_config | to_nice_json }}&quot;\r\n      notify: restart docker\r\n\r\n  handlers:\r\n    - name: restart docker\r\n      systemd:\r\n        name: docker\r\n        state: restarted\r\n        daemon_reload: yes\r\n<\/pre>\n<p>\u305d\u3057\u3066\u5b9f\u884c<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nansible-playbook update_daemon_json.yml\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Ansible \u3067 \/etc\/docker\/daemon.json \u30d5\u30a1\u30a4\u30eb\u3092\u3044\u3058\u3063\u305f\u306e\u3067\u30e1\u30e2\u3002 slurp moduel \u3092\u4f7f\u3063\u3066 JSON \u30d5\u30a1\u30a4\u30eb\u3092\u66f8\u304d\u63db\u3048\u305f\u3002 \u307e\u305a\u306f ansible \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,8],"tags":[],"class_list":["post-2137","post","type-post","status-publish","format-standard","hentry","category-docker","category-linux"],"_links":{"self":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/comments?post=2137"}],"version-history":[{"count":2,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2137\/revisions"}],"predecessor-version":[{"id":2139,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/posts\/2137\/revisions\/2139"}],"wp:attachment":[{"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/media?parent=2137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/categories?post=2137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kwonline.org\/memo2\/wp-json\/wp\/v2\/tags?post=2137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}