要复制Ansible命令的输出,可以使用Ansible的debug模块。下面是一个示例,演示如何复制4个命令的输出:
- hosts: your_target_hosts
gather_facts: false
tasks:
- name: Run command 1
shell: your_command_1
register: result_1
- name: Run command 2
shell: your_command_2
register: result_2
- name: Run command 3
shell: your_command_3
register: result_3
- name: Run command 4
shell: your_command_4
register: result_4
- name: Print command outputs
debug:
msg:
- "{{ result_1.stdout }}"
- "{{ result_2.stdout }}"
- "{{ result_3.stdout }}"
- "{{ result_4.stdout }}"
在上面的示例中,我们使用Ansible的shell模块运行了4个命令,并分别将命令的输出保存到result_1、result_2、result_3和result_4变量中。然后使用debug模块打印出这些命令的输出。
你可以将上面的代码保存为一个YAML文件,然后使用ansible-playbook命令运行该Playbook。请将your_target_hosts
替换为你想要运行命令的目标主机的名称或IP地址,将your_command_1
、your_command_2
、your_command_3
和your_command_4
替换为你想要运行的实际命令。
运行该Playbook后,你将在终端上看到4个命令的输出。你也可以将输出保存到文件中,以供后续使用。