I want to add below docker log rotation specs into daemon.json file using ansible-playbook
"log-driver": "json-file",
"log-opts": {
"max-size": "1m",
"max-file": "4"
}
What if daemon.json is already present on the node which I am applying the playbook to. I dont want to mess up existing configuration. How do I add above block at line no. 2 ( that is after ‘{‘ or before last line i.e. ‘}’ ) ?
3
Answers
You can use the
lineinfile
moduleI’d use for blocks blockinfile:
ansible.builtin.lineinfile
ansible.builtin.blockinfile
As @malpanez explains, I think it would be more accurate to use the
ansible.builtin.blockinfile
module for this. You can look at the example usage from the link below.https://docs.ansible.com/ansible/latest/collections/ansible/builtin/blockinfile_module.html