# Test before remote daemon restart?

**URL:** <https://forum.ansible.com/t/test-before-remote-daemon-restart/41878>\
**Category:** Get Help\
**Tags:** ubuntu\
**Created:** [April 22, 2025, 2:46pm UTC](https://forum.ansible.com/t/test-before-remote-daemon-restart/41878 "2025-04-22T14:46:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![quist](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/quist/32/1169_2.png) [@quist](https://forum.ansible.com/u/quist)\
**Post date:** [April 22, 2025, 2:46pm UTC](https://forum.ansible.com/t/test-before-remote-daemon-restart/41878/1 "2025-04-22T14:46:05Z")

</div>

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.

```auto
- 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.

Thanks!

---

<div class="post-metadata">

**Author:** ![Lyle\_McKarns](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/lyle_mckarns/32/8142_2.png) [@Lyle\_McKarns](https://forum.ansible.com/u/Lyle_McKarns)\
**Post date:** [April 22, 2025, 2:54pm UTC](https://forum.ansible.com/t/test-before-remote-daemon-restart/41878/2 "2025-04-22T14:54:04Z")

</div>

`ansible.builtin.copy` has the [validate](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html#parameter-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](https://docs.ansible.com/ansible/latest/reference_appendices/faq.html#complex-configuration-validation) 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.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![chris](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/chris/32/293_2.png) [@chris](https://forum.ansible.com/u/chris)\
**Post date:** [April 23, 2025, 4:53pm UTC](https://forum.ansible.com/t/test-before-remote-daemon-restart/41878/3 "2025-04-23T16:53:08Z")

</div>

In the [Ansible unbound role I have written](https://git.coop/webarch/unbound) I use [unbound-checkconf](https://www.nlnetlabs.nl/documentation/unbound/unbound-checkconf/) via the `ansible.builtin.command` module for this:

```yaml
    - name: Check Unbound config
      ansible.builtin.command: unbound-checkconf
      environment:
        PATH: /usr/sbin:/usr/bin:/sbin:/bin
      check_mode: false
      changed_when: false

```
