4

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 }}"
error404
  • 2,684
  • 2
  • 13
  • 21
Haris
  • 85
  • 2
  • 9

2 Answers2

2

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.

Paulie-C
  • 1,674
  • 1
  • 13
  • 29
Haris
  • 85
  • 2
  • 9
1

use !unsafe

enter link description here

Julio Marins
  • 10,039
  • 8
  • 48
  • 54