Ansible Print Debug Msg Variable
Answer :
Solution 1:
Try this:
- name: Print mosh version   debug: "msg=Mosh Version: '{{ mosh_version.stdout }}'"   More info in http://docs.ansible.com/YAMLSyntax.html#gotchas
Edited: Something like this works perfect for me:
- name: Check Ansible version   command: ansible --version   register: ansibleVersion  - name: Print version   debug:     msg: "Ansible Version: {{ ansibleVersion.stdout }}"   http://pastie.org/private/cgeqjucn3l5kxhkkyhtpta
Solution 2:
Simplest answer
- debug: var=mosh_version.stdout   Solution 3:
I have displayed variable and message in the debug same task.
Ansible Task
- name: Report the /boot/initramfs file status for latest installed kernel   debug:     msg: "{{ ansible_hostname }} =  {{INITRAMFS_LAST_KERNEL.stdout}}"       Output
TASK [os-upgrade.linux : Report the /boot/initramfs file status for latest installed kernel] ******************************************* ok: [ANSIBLENODE] => {     "msg": "ANSIBLENODE =  /boot/initramfs-3.10.0-1062.12.1.el7.x86_64.img" }   Solution 4:
Just remove the colon
debug: msg="Mosh Version {{ mosh_version.stdout }}"   Solution 5:
Anytime I have problems with special characters in Ansible strings/cmds I do this:
- Wrap with single quotes
 - Wrap with double curly brackets
 
So your standard colon becomes {{':'}}
And your task becomes:
- debug: msg="Ansible Version{{':'}} {{ ansibleVersion.stdout }}"   Again this works for most special characters, even strings. Consider the following:
docker ps --format '{{.Names}}'   In order to run this in Ansible, just apply the same logic, the following task executes as expected:
- name: Get the docker container names   become: yes   shell: "docker ps --format '{{'{{'}}.Names{{'}}'}}'"   register: docker_containers  
Comments
Post a Comment