设为首页 加入收藏

TOP

Playbook剧本小结(五)
2019-09-24 11:16:57 】 浏览:161
Tags:Playbook 剧本 小结
ver - name: Service Nfs Server service: name=nfs-server state=started enabled=yes tags: start_nfs-server #正常执行playbook [root@manager ~]# ansible-playbook f10.yml PLAY [all] ******************************************************************************************************************************** TASK [Gathering Facts] ******************************************************************************************************************** ok: [10.0.0.30] TASK [Install Nfs Server] ***************************************************************************************************************** ok: [10.0.0.30] TASK [Service Nfs Server] ***************************************************************************************************************** ok: [10.0.0.30] PLAY RECAP ******************************************************************************************************************************** 10.0.0.30 : ok=3 changed=0 unreachable=0 failed=0

使用-t指定tags执行, 多个tags使用逗号隔开即可

[root@manager ~]# ansible-playbook -t install_nfs-server f10.yml

PLAY [all] ********************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************
ok: [10.0.0.30]

TASK [Install Nfs Server] *****************************************************************************************************************
ok: [10.0.0.30]

PLAY RECAP ********************************************************************************************************************************
10.0.0.30                  : ok=2    changed=0    unreachable=0    failed=0

使用--skip-tags排除不执行的tags

[root@manager ~]# ansible-playbook --skip-tags install_nfs-server f10.yml

PLAY [all] ********************************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************************
ok: [10.0.0.30]

TASK [Service Nfs Server] *****************************************************************************************************************
ok: [10.0.0.30]

PLAY RECAP ********************************************************************************************************************************
10.0.0.30                  : ok=2    changed=0    unreachable=0    failed=0

8.Playbook Handlers

playbook安装Apache示例

[root@m01 ~]# cat webserver.yml 
- hosts: web
  remote_user: root
#1.定义变量,在配置文件中调用
  vars:
    http_port: 8881

#2.安装httpd服务
  tasks:
    - name: Install Httpd Server
      yum: name=httpd state=present

#3.使用template模板,引用上面vars定义的变量至配置文件中
    - name: Configure Httpd Server
      template: src=./httpd.conf dest=/etc/httpd/conf/httpd.conf
      notify: Restart Httpd Server

#4.启动Httpd服务
    - name: Start Httpd Server
      service: name=httpd state=started enabled=yes

#5.检查Httpd服务当前的运行的端口状态
    - name: Get Httpd Server Port
      shell: netstat -lntp|grep httpd
      register: Httpd_Port

#6.输出Httpd运行的状态至面板
    - name: Out Httpd Server Status
      debug: msg={{ Httpd_Port.stdout_lines }}
      ignore_errors
首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇记录SQL Server中一次无法重现的.. 下一篇松软科技web课堂:SQLServer之MIN(..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目