我正在尝试在Ansible中以一种很好的格式显示debug命令的消息输出。目前,输出是这样的:
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" }
如何去掉'\n‘字符并换成新行?使用 split('\n') 的以下代码不起作用。
split('\n')
- 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: