# junos\_template in Ansible 2.1

**URL:** <https://forum.ansible.com/t/junos-template-in-ansible-2-1/21398>\
**Category:** Ansible Project\
**Created:** [May 10, 2016, 11:44pm UTC](https://forum.ansible.com/t/junos-template-in-ansible-2-1/21398 "2016-05-10T23:44:18Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ian\_Cote](https://avatars.discourse-cdn.com/v4/letter/i/c67d28/32.png) [@Ian\_Cote](https://forum.ansible.com/u/Ian_Cote)\
**Post date:** [May 10, 2016, 11:44pm UTC](https://forum.ansible.com/t/junos-template-in-ansible-2-1/21398/1 "2016-05-10T23:44:18Z")

</div>

I’ve been kicking the tires on 2.1, specifically to start managing network equipment. I’ve had success with the junos\_command and junos\_config modules, but cannot get the junos\_template module to work for even a trivial example. I’ve tried the set and text formats -

config.set:  
set system host-name {{ inventory\_hostname }}

config.j2 (which according to the -vvv output was treated as text):  
system {  
host-name {{ inventory\_hostname }}  
}

The error is “msg”: “Unable to load config: ConfigLoadError(severity: error, bad\_element: junos.set, message: error: unknown command)” which is odd since using the juniper\_config module with the lines: - set system host-name {{ inventory\_hostname }} works fine.

Could someone post a (preferably text form) juniper template that they have had success with? I’m looking to merge the config here at first.

Thanks,  
-ian

---

<div class="post-metadata">

**Author:** ![Ian\_Cote](https://avatars.discourse-cdn.com/v4/letter/i/c67d28/32.png) [@Ian\_Cote](https://forum.ansible.com/u/Ian_Cote)\
**Post date:** [May 13, 2016, 5:28pm UTC](https://forum.ansible.com/t/junos-template-in-ansible-2-1/21398/2 "2016-05-13T17:28:12Z")

</div>

OK, I figured out what I was doing wrong. I had the template in a role, but was calling the module from a top level play. Moving the module call to the role’s tasks/main.yml or moving the template to the top level dir fixed the issue.

Makes more sense to have the call go in with the role anyways, this was more of a bug in testing :-/

---

<div class="post-metadata">

**Author:** ![Dat\_Dao](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Dat\_Dao](https://forum.ansible.com/u/Dat_Dao)\
**Post date:** [March 12, 2017, 3:39pm UTC](https://forum.ansible.com/t/junos-template-in-ansible-2-1/21398/3 "2017-03-12T15:39:29Z")

</div>

Hi IAN,  
I am a newbie in ansible sector, I wrote the playbook in which I used junos\_template module, but when I run playbook, I got this error:  
he error is “msg”: “Unable to load config: ConfigLoadError(severity: error, bad\_element: junos.set, message: error: unknown command)” which is odd since using the juniper\_config module with the lines: - set system host-name {{ inventory\_hostname }} works fine.

This is my jinja2 file:

configure  
set system hostname DAT123  
commit

and here is my playbook:

---

<div class="post-metadata">

**Author:** ![psprygada](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@psprygada](https://forum.ansible.com/u/psprygada)\
**Post date:** [March 12, 2017, 8:21pm UTC](https://forum.ansible.com/t/junos-template-in-ansible-2-1/21398/4 "2017-03-12T20:21:53Z")

</div>

only include configuration statements in your file (config.j2), not cli commands. remove the configure and commit statements

---

<div class="post-metadata">

**Author:** ![Dat\_Dao](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Dat\_Dao](https://forum.ansible.com/u/Dat_Dao)\
**Post date:** [March 13, 2017, 1:47am UTC](https://forum.ansible.com/t/junos-template-in-ansible-2-1/21398/5 "2017-03-13T01:47:33Z")

</div>

Dear Peter,  
Thanks for your response, but can you explain about the argument src in the junos\_template.  
I don’t know what do we fill after src’s colon? the path or the file name?  
In my ansible, I creat config.j2 at /etc/ansible folder.  
So Can I fill:  
src: /etc/ansible/config.j2  
Or:  
src: config.j2

And I have another problem, I read junos\_template’documentation, at the src entry wrote below:  
“The path to the config source. The source can be either a file with config or a template that will be merged during runtime. By default the task will search for the source file in role or playbook root folder in templates directory.”

So it’s mean the config soure must to be create at /etc/ansible/roles?

---

<div class="post-metadata">

**Author:** ![Dat\_Dao](https://avatars.discourse-cdn.com/v4/letter/d/f4b2a3/32.png) [@Dat\_Dao](https://forum.ansible.com/u/Dat_Dao)\
**Post date:** [March 13, 2017, 8:53am UTC](https://forum.ansible.com/t/junos-template-in-ansible-2-1/21398/6 "2017-03-13T08:53:54Z")

</div>

Yeah! I fixed my issue, thank you very much.  
After I changed the tail of file from .j2 to .set, my playbook worked fine.

But now, I have another problem, when run my playbook with config.set:  
set interfaces ge-/0/0/5.1 family inet address [1.1.1.1/32](http://1.1.1.1/32)  
set interfaces ge-/0/0/5.1 vlan-id 51

===\> FAIL

Then I changed as below:

set interfaces ge-/0/0/5.1 vlan-id 51

set interfaces ge-/0/0/5.1 family inet address [1.1.1.1/32](http://1.1.1.1/32)

===\> OK

Its mean that when one comment run, system will commit immediately and then implement the next comment.  
So How I can do to commit comment after all?
