此问题可能是由于复杂的Ansible输出格式造成的。以下是解决此问题的一些示例方法:
- name: Install Apache
apt:
name: apache2
state: present
register: install_apache
- debug:
var: install_apache.stdout_lines | map('regex_replace', '^(.*)$', '\\1\\n') | list
- name: Install Apache
apt:
name: apache2
state: present
register: install_apache
no_log: true
- name: Save output to file
copy:
content: "{{ install_apache.stdout_lines }}"
dest: /tmp/install_apache_output
- name: Read output from file
shell: cat /tmp/install_apache_output
register: install_apache_output
- debug:
var: install_apache_output.stdout_lines
- name: Install Apache
apt:
name: apache2
state: present
register: install_apache
- name: Parse Output using json_query
debug:
var: install_apache | json_query('stdout_lines')
以上示例中,第一个方法使用map和regex_replace过滤器格式化输出,第二个方法将输出保存到文件并读取输出以进行解析,第三个方法使用json_query过滤器解析输出。根据具体情况选择合适的方法。
下一篇:Ansible输出详细更改的问题