Ansible, validate a custom configuration file

85 views
Skip to first unread message

Valentino Gagliardi

unread,
Jun 6, 2014, 8:39:32 AM6/6/14
to ansible...@googlegroups.com

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.

Brian Coca

unread,
Jun 6, 2014, 8:45:23 AM6/6/14
to ansible...@googlegroups.com
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.

--
Brian Coca
Stultorum infinitus est numerus
0110000101110010011001010110111000100111011101000010000001111001011011110111010100100000011100110110110101100001011100100111010000100001
Pedo mellon a minno

Servermanaged

unread,
Jun 6, 2014, 9:13:35 AM6/6/14
to ansible...@googlegroups.com
Thank you!


--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/RLbH3TnZ5R0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CADn%2BHsx7_NAt_ecNh7u9VoXDbNP35d7pQ5gt7y539iW6M-Gqjg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages