Reputation: 983
I am trying to display the message output of a debug command in a nice format in Ansible. At the moment this is how the output looks:
TASK [stop : Report Status of Jenkins Process] *******************************************************************************************************************************
ok: [localhost] => {
"msg": "Service Jenkins is Running.\nReturn code from `grep`:\n0\n"
}
TASK [stop : debug] **********************************************************************************************************************************************************
ok: [localhost] => {
"msg": {
"changed": false,
"failed": false,
"msg": "Service Jenkins is Running.\nReturn code from `grep`:\n0\n"
}
}
How do I get rid of the '\n' character and replace with a new line?
The code below using the split('\n')
does not work.
- name: Checking Jenkins Process
shell: "ps -ef | grep -v grep | grep -v dhclient | grep jenkins"
ignore_errors: yes
register: jenkins_process
- debug:
var: jenkins_process.rc
- name: Report Status of Jenkins Process
fail:
msg: |
Service Jenkins is not found
Return code from `grep`:
{{ jenkins_process.rc }}
when: jenkins_process.rc != 0
register: report
- name: Report Status of Jenkins Process
debug:
msg: |
Service Jenkins is Running.
Return code from `grep`:
{{ jenkins_process.rc }}
when: jenkins_process.rc == 0
register: report
- debug:
msg: "{{ report.split('\n') }}"
- name: Stop Jenkins Service
service:
name: jenkins
state: stopped
Is there a way to display this in a nice way?
Upvotes: 3
Views: 8816
Reputation: 12497
You can use the debug callback plugin.
You can specify it on command line:
ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook ...
Or in your default
section of your ansible.cfg
configuration file:
stdout_callback = debug
Upvotes: 6