栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

ansible-playbook变量注册

ansible-playbook变量注册

编写一个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 }}

执行结果:

 

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/735542.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号