我正在尝试在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')
的以下代码不起作用。
- 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
有没有一种很好的方式来显示它呢?
发布于 2019-03-01 18:50:58
您可以使用debug回调插件。
您可以在命令行中指定它:
ANSIBLE_STDOUT_CALLBACK=debug ansible-playbook ...
或者在ansible.cfg
配置文件的default
部分:
stdout_callback = debug
https://stackoverflow.com/questions/54937600
复制相似问题