junos_template in Ansible 2.1

122 views
Skip to first unread message

Ian Cote

unread,
May 12, 2016, 1:10:44 PM5/12/16
to Ansible Project, ian...@uw.edu
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

Ian Cote

unread,
May 13, 2016, 1:28:13 PM5/13/16
to Ansible Project, ian...@uw.edu
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 :-/

Dat Dao

unread,
Mar 12, 2017, 11:51:25 AM3/12/17
to Ansible Project, ian...@uw.edu
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:
---
- name: cau hinh doi hostname
  hosts: juniper


 tasks:
 - name: tai config
   junos_template:
     src: config.j2
     host: 100.100.100.100

Please help me fix this issue.


Vào 00:10:44 UTC+7 Thứ Sáu, ngày 13 tháng 5 năm 2016, Ian Cote đã viết:

Peter Sprygada

unread,
Mar 12, 2017, 4:21:58 PM3/12/17
to ansible...@googlegroups.com, ian...@uw.edu
only include configuration statements in your file (config.j2), not cli commands.  remove the configure and commit statements

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/c34975a6-0c04-491e-b20a-259115e73ca7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dat Dao

unread,
Mar 12, 2017, 9:47:48 PM3/12/17
to ansible...@googlegroups.com
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?


Regards,

***********************************************************************************
Đào Minh Đạt
Mail: datda...@gmail.com
Tel: 01265 332 116
Add: 16/72/11, Nguyễn Thiện Thuật, phường 3, Quận 3, Tp.Hồ Chí Minh
***********************************************************************************

--
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/l2b3Gy41UGI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.

To post to this group, send email to ansible-project@googlegroups.com.

Dat Dao

unread,
Mar 13, 2017, 4:53:58 AM3/13/17
to ansible...@googlegroups.com
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
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

===> 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?

Regards,

***********************************************************************************
Đào Minh Đạt
Mail: datda...@gmail.com
Tel: 01265 332 116
Add: 16/72/11, Nguyễn Thiện Thuật, phường 3, Quận 3, Tp.Hồ Chí Minh
***********************************************************************************

Reply all
Reply to author
Forward
0 new messages