Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template error while templating string: unexpected char u - Ansible

When executing a playbook to run a command in a remote host and pass the output using shell, getting below error.

fatal: [master1]: FAILED! => {} MSG: template error while templating string: unexpected char u'a' at 4. String: {{54aa7fda16833bff8358b6bd1157df2d9caa26b2}}

Below is my playbook content

- name: 'Play1' 

  hosts: master 

  tasks: 

   - name: 'Execute command' 

     shell: ''sh generate_ticket.sh" #command to generate ticket 

     register: shell_output 

   - name: 'debug shell_output' 

     debug: 

      var="{{ shell_output.stdout | from_yaml }}"

When I try the same with msg and don't try to filter then the output is printed without any error. However I prefer to use var as it suits best for my further requirements. If the ticket number is a different string I do not face any issues. Please see below:

Output:

ok: [master1] => {}


MSG:


54aa7fda16833bff8358b6bd1157df2d9caa26b2


Playbook :

- name: 'Play1' 

  hosts: master 

  tasks: 

   - name: 'Execute command' 

     shell: ''sh generate_ticket.sh" #command to generate ticket 

     register: shell_output 

   - name: 'debug shell_output' 

     debug: msg="{{ shell_output.stdout | from_yaml }}"
like image 403
Haris Avatar asked Sep 06 '25 02:09

Haris


2 Answers

It seems to work when I put single quotes around shell_output.stdout

var="{{ 'shell_output.stdout' | from_yaml}}"

Let me know if anybody has a better fix than this.

like image 154
Haris Avatar answered Sep 09 '25 19:09

Haris


use !unsafe

enter link description here

like image 22
Julio Marins Avatar answered Sep 09 '25 19:09

Julio Marins