debug: msg: "{{ command_output.stdout_lines | select('regex', '^specific_pattern') | list }}" 在上述示例中,首先使用command模块执行一个命令,并将输出结果存储在command_output变量中。然后使用debug模块打印出通过过滤和处理stdout_lines变量获取的特定行。 需要注意的是,your_command需要替换为实际的...
可以看到debug不光输出了date命令结果,还返回了很多相关调试信息,只需要date返回值,可以使用变量属性过滤 如:result.stdout 就是命令的返回值。 程序改成: - name: Print debug infomation eg hosts: test2 gather_facts: F tasks: - name: Command run line shell:date register: result - name: Show debug i...
以下是使用Ansible时访问stdout_lines的示例代码: 代码语言:txt 复制 - name: 执行命令并获取输出 hosts: target_hosts tasks: - name: 执行命令 command: your_command register: command_output - name: 打印输出内容 debug: var: command_output.stdout_lines 在上述示例中,your_command是要执行的命令,target_...
"stderr": "Shared connection to test-liuchao-01-vm closed.\r\n", "stderr_lines": [ "Shared connection to test-liuchao-01-vm closed." ], "stdout": "result: I am on host [test-liuchao-01-vm]\r\n", "stdout_lines": [ "result: I am on host [test-liuchao-01-vm]" ] } ...
"stdout": "server231.localdomain", "stdout_lines": [ "server231.localdomain" ] } } TASK [debug] *** ok: [172.16.213.231] => { "host_result": { "changed": true, "cmd": "hostname", "delta": "0:00:00.007228", "end": "...
stdout_lines:按换行符分割输出的内容,在多行输出时,结果更加直观 实例2:直接输出变量的值 --- - name: Check the user hosts: 192.168.37.10 tasks: - name: View the logged in user name shell: whoami register: user - debug: msg: "{{user.stdout}}" ...
我在运行ad-hoc命令时得到了太多的输出,我只想将输出限制在stdout_lines或stdout,是否有一种方法可以做到这一点,而不需要创建带有debug的特定剧本或任何其他模块,只需添加一个选项或将输出传输到grep?发布于 8 月前 ✅ 最佳回答: ansible adoc命令没有内置选项来过滤输出,除非模块本身支持(如设置模块)。 如果您...
debug:var: cmd_output.stdout_lines user 模块:用于在远程主机上创建、修改和删除用户账号。- name: Add a user user:name: john state: present groups: sudo password: '$6$cIHiW1dL$eQ0H6ptZm5gr'- name: Remove a user user:name: john state: absent yum 模块:用于在 CentOS 和 Red Hat 等系统...
stdout_lines:按换行符分割输出的内容,在多行输出时,结果更加直观 我们可以在 playbook 中,很方便地调用这些输出。 编写playbook,在 playbook 中调用 register 变量中的输出,然后调用该变量的输出信息,打印出一条消息: it@workstation:~/ansible$ vim test.yml ...
copy: src=files/daemon.json dest=/etc/docker/daemon.json - name: 启动docker systemd: name=docker state=restarted enabled=yes daemon_reload=yes - name: 查看状态 shell: docker info register: docker - debug: var=docker.stdout_lines...