编写一个yml脚本:
[root@proxy httpd]# cat regisger.yml
- hosts: webservers
remote_user: root
tasks:
- name: Install Httpd Server
yum: name=httpd state=present
- name: Startup Http Server
service: name=httpd state=started
- name: Check Httpd Server
# 使用shell执行命令
shell: ps aux | grep httpd
#将执行命令的结果存储至check_httpd变量中
register: check_httpd
# 通过debug模块,msg方法输出所有内容
- name: output variables
debug:
msg: "{{ check_httpd.stdout_lines }}"
执行这个脚本ansible-playbook reigster.yml
编写一个查看所有主机监听状态的yml脚本,通过注册变量NetTcpInfo把shell命令ss -tnlp的结果,通过debug模块输出到执行终端:
[root@proxy httpd]# cat register2.yml
- hosts: all
tasks:
- name: Get Network TCP Connection Listen Information
shell: ss -tnlp
register: NetTcpInfo
- name: Get NetWork Status
debug: msg={{ NetTcpInfo.stdout_lines }}
执行结果:



