通过ansible -i host all -m ping 命令跑集群后,如何将输出结果输入一个文件
时间: 2024-03-01 18:51:47 浏览: 18
您可以使用重定向符号将 Ansible 的 ping 模块的输出结果写入到文件中,例如:
```
ansible -i hosts all -m ping > output.txt
```
这将运行 ping 模块并将输出结果写入到 output.txt 文件中。请确保在运行命令时当前目录具有写入权限。
相关问题
通过ansible -i host all -m shell -a "cat /etc/passwd"命令跑集群后,如何将输出结果输入一个文件
您可以使用重定向符号将命令的输出结果写入到文件中,例如:
```
ansible -i hosts all -m shell -a "cat /etc/passwd" > output.txt
```
这将运行命令`cat /etc/passwd`并将其输出结果写入到`output.txt`文件中。请确保在运行命令时当前目录具有写入权限。
通过ansible跑ping命令,如何将输出结果写入一个文件中
可以使用Ansible的"shell"模块来运行ping命令,并使用"register"参数将输出结果保存到一个变量中。然后,可以使用"copy"模块将这个变量中的内容写入到一个文件中。以下是一个示例:
```
- name: Run ping command and save output to a variable
shell: ping -c 4 google.com
register: ping_output
- name: Write ping output to a file
copy:
content: "{{ ping_output.stdout }}"
dest: /path/to/file.txt
```
这将运行"ping -c 4 google.com"命令,并将输出结果保存到变量"ping_output"中。然后,使用"copy"模块将"ping_output.stdout"中的内容写入到指定的文件中。