I have a cron based script which based on local changes, generates a configuration file (in my case for unbound) and them via ansible pushes/copies it off to several institutional caching dns servers, restarting the daemon if necessary.
- name: Write some files to be included for unbound
ansible.builtin.copy:
src: "files/unbound/{{item}}"
dest: "{{remote_dir}}"
backup: true
owner: root
notify: Restart unbound
etc..
Is there some builtin ansible methods for testing the config file (even locally) say for syntax errors before copying and restarting? Otherwise some very bad things happen on the far end.
ansible.builtin.copy has the validate option. This allows you to call out to an on-system tool to validate the config file before the copy is completed.
If the application you’re trying to use to validate can’t you alternate/temp files, there is also documentaiton on how to do that process yourself.
It involves copying the file, running the test, and then reverting that copy if the test does not pass.