# group\_vars and templates

**URL:** <https://forum.ansible.com/t/group-vars-and-templates/13383>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [August 29, 2013, 9:18pm UTC](https://forum.ansible.com/t/group-vars-and-templates/13383 "2013-08-29T21:18:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Lucas](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@Michael\_Lucas](https://forum.ansible.com/u/Michael_Lucas)\
**Post date:** [August 29, 2013, 9:18pm UTC](https://forum.ansible.com/t/group-vars-and-templates/13383/1 "2013-08-29T21:18:15Z")

</div>

Hi,

I'm using a simple template to generate sshd\_config. It works well for  
a single operating system, but when I try to add a second it breaks.

It appears that the jinja2 template is not pulling in the group\_vars  
for the operating system group.

Here's a playbook snippet:

&nbsp;&nbsp;- name: sshd configuration file update  
&nbsp;&nbsp;&nbsp;&nbsp;template: src=/home/ansible/crossplatform/etc/ssh/common-sshd\_config.j2  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;dest=/etc/ssh/sshd\_config  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;backup=yes  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;owner=0 group=0 mode=0644  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;validate='/usr/sbin/sshd -T -f %s'  
&nbsp;&nbsp;&nbsp;&nbsp;notify:  
&nbsp;&nbsp;&nbsp;&nbsp;- restart sshd

When I run this task, I get:

TASK: [sshd configuration file update] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [mwltest3.lodden.com] =\> {'msg': "unsupported operand type(s) for -: 'StrictUndefined' and 'StrictUndefined'", 'failed': True}  
fatal: [mwltest3.lodden.com] =\> {'msg': "unsupported operand type(s) for -: 'StrictUndefined' and 'StrictUndefined'", 'failed': True}

FATAL: all hosts have already failed -- aborting

As far as I can see, this means that some variable is undefined in the  
template.

The template is:

#$Id$  
#{{ ansible\_managed }}

ListenAddress {{ ansible\_ssh\_host }}

AuthorizedKeysFile /etc/ssh/authorized\_keys/%u

PasswordAuthentication no  
ChallengeResponseAuthentication no  
UsePAM yes

Subsystem sftp {{ program-sftp-server }}

I have group\_vars/freebsd and group\_vars/ubuntu files, and these files  
define the program-sftp-server variable like so

---

<div class="post-metadata">

**Author:** ![James\_Cammarata1](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@James\_Cammarata1](https://forum.ansible.com/u/James_Cammarata1)\
**Post date:** [August 29, 2013, 10:13pm UTC](https://forum.ansible.com/t/group-vars-and-templates/13383/2 "2013-08-29T22:13:15Z")

</div>

You’re using dashes in the variable name, you need to convert those to underscores or remove them.

---

<div class="post-metadata">

**Author:** ![Michael\_Lucas](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@Michael\_Lucas](https://forum.ansible.com/u/Michael_Lucas)\
**Post date:** [August 30, 2013, 12:46pm UTC](https://forum.ansible.com/t/group-vars-and-templates/13383/3 "2013-08-30T12:46:41Z")

</div>

Worked perfectly, thanks for the pointer.

It's this sort of little thing that drives you nuts...
