# Ansible, validate a custom configuration file

**URL:** <https://forum.ansible.com/t/ansible-validate-a-custom-configuration-file/15418>\
**Category:** Ansible Project\
**Created:** [June 6, 2014, 12:39pm UTC](https://forum.ansible.com/t/ansible-validate-a-custom-configuration-file/15418 "2014-06-06T12:39:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Servermanaged](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Servermanaged](https://forum.ansible.com/u/Servermanaged)\
**Post date:** [June 6, 2014, 12:39pm UTC](https://forum.ansible.com/t/ansible-validate-a-custom-configuration-file/15418/1 "2014-06-06T12:39:32Z")

</div>

Hello there  
already asked on IRC with no luck.

In Ansible It is possibile to pass a custom filename to validate=‘’ rather than %s? I need to validate a main conf file which is not the templated one.

While this works fine but is not the intended behavior because it validate only {{ icinga2\_hosts\_dir }}{{ hostvars[item][‘ansible\_fqdn’] }}.conf :

- name: Copy Host Definitions  
template: src=host\_def.j2  
dest={{ icinga2\_hosts\_dir }}{{ hostvars[item][‘ansible\_fqdn’] }}.conf  
owner=root  
group=root  
mode=0644  
validate=‘/usr/sbin/icinga2 -C -c %s’  
with\_items: groups[“{{ hosts }}”]  
notify:
- reload icinga2

This is what I want instead but gives me an error:

- name: Copy Host Definitions  
template: src=host\_def.j2  
dest={{ icinga2\_hosts\_dir }}{{ hostvars[item][‘ansible\_fqdn’] }}.conf  
owner=root  
group=root  
mode=0644  
validate=‘/usr/sbin/icinga2 -C -c /etc/icinga2/icinga2.conf’  
with\_items: groups[“{{ hosts }}”]  
notify:
- reload icinga2

Error:

File “/root/.ansible/tmp/ansible-tmp-1402058068.06-202801895532086/copy”, line 207, in main  
(rc,out,err) = module.run\_command(validate % src)  
TypeError: not all arguments converted during string formatting

Thank you.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [June 6, 2014, 12:45pm UTC](https://forum.ansible.com/t/ansible-validate-a-custom-configuration-file/15418/2 "2014-06-06T12:45:20Z")

</div>

validate is intended to do so on the file you are copying/templating BEFORE  
it is put into place. It does not work for 'multi file configs' as the main  
file will not be pointing to the tmpfile that you are processing, which  
defeats the purpose of the whole thing.

If you want to validate existing configuration, you can just use the shell  
module.

---

<div class="post-metadata">

**Author:** ![Servermanaged](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Servermanaged](https://forum.ansible.com/u/Servermanaged)\
**Post date:** [June 6, 2014, 1:13pm UTC](https://forum.ansible.com/t/ansible-validate-a-custom-configuration-file/15418/3 "2014-06-06T13:13:32Z")

</div>

Thank you!
