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.
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 :-/
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.
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?
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?