---
- hosts: all
gather_facts: no
tasks:
- name: 注册hostname_result变量
shell: hostname
register: hostname_result
- name: 显示结果
debug: msg="{{hostname_result.stdout}} => {hostname_result.cmd}}"
- 第一个shell执行完后,使用register获取数据到hostname_result里
- hostname_result是一个key value字典
- debug输出hostname_result.stdout和hostname_result.cmd的具体内容
本文介绍如何在Ansible中使用shell模块执行命令并注册结果到变量,通过debug模块输出详细信息,包括命令及其执行结果。
2276

被折叠的 条评论
为什么被折叠?



