0

GOAL

  • I want to create a portable role folder that utilizes textfsm templates in role directory.
  • Directory structure
$ tree
.
├── ansible.cfg
├── hosts.ini
├── out_pb1
├── pb1.yml
├── roles
│   ├── command_facts
│   │   ├── tasks
│   │   │   └── main.yml
│   │   ├── templates
│   │   │   └── textfsm   // I want this
│   │   └── vars
└── templates
    └── textfsm   // created for testing

PROBLEM

  • parse_cli_textfsm is referencing to templates/textfsm instead of roles/command_facts/templates/textfsm
  • The goal is portability so specifying full path is not considered.

ATTEMPTS TO FIX (FAIL)

  • Executes pb1.yml
  • Error shown as below if I deleted templates/textfsm in the pb1.yml directory.
$ ansible-playbook pb1.yml -u username -k
(omitted)
TASK [command_facts : set_fact]
fatal: [target]: FAILED! => {"msg": "unable to locate parse_cli_textfsm template: /templates/textfsm"}
  • I tried to utilize system variable role_path that is {{ raw_output.stdout | parse_cli_textfsm('{{ role_path }}/templates/textfsm') }} but it is not working. {{ role_path }} turns into a normal string.
$ ansible-playbook pb1.yml -u username -k
(omitted)
TASK [ixrs_facts : set_fact] 
fatal: [target]: FAILED! => {"msg": "unable to locate parse_cli_textfsm template: {{ role_path }}/templates/textfsm"}

FILES

  • roles/command_facts/task/main.yml
---
- name: show protocols all
  raw: "show protocols all"
  register: raw_output
- set_fact:
    output: {{ raw_output.stdout | parse_cli_textfsm("/templates/textfsm") }}
- debug: var=output[::]
  • pb1.yml
---
- name: testing
  hosts: target
  gather_facts: false
  roles:
    - { role: command_facts }

REFERENCE

kstack
  • 1

1 Answers1

0

Use this: parse_cli_textfsm('{{ role_path +“/templates/textfsm“) }}

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
Ben
  • 1