zoukankan      html  css  js  c++  java
  • ansible-playbook案例

    本案例要求:

    • 安装Apache并修改监听端口为8080
    • 修改ServerName配置,执行apachectl -t命令不报错
    • 设置默认主页hello world
    • 启动服务并设开机自启

       

    ---
    - hosts: cache
      remote_user: root
      tasks:
        - name: install one specific version of Apache
          yum:
            name: httpd        //安装Apache
            state: installed
        - lineinfile:
            path: /etc/httpd/conf/httpd.conf
            regexp: '^Listen '
            line: 'Listen 8080'        //修改端口为8080
        - replace:
            path: /etc/httpd/conf/httpd.conf
            regexp: '^#(ServerName).*'        //配置ServerName
            replace: '1 localhost'
        - service:
            name: httpd
            enabled: yes        //开机自启
            state: restarted
        - copy:
            src: /root/index.html        //修改主页,可以自己写个页面
            dest: /var/www/html/index.html

    扩展的一个tags和notify以及handlers

    ---
    - hosts: web1
      remote_user: root
      tasks:
        - name: install the latest version of Apache
          yum:
            name: httpd
            state: latest
        - replace:
            path: /etc/httpd/conf/httpd.conf
            regexp: '(^Listen).*'
            replace: '1 8080'
            backup: yes
        - replace:
            path: /etc/httpd/conf/httpd.conf
            regexp: '(^#ServerName ).*'
            replace: '1 localhost'
            backup: yes
        - copy:
            src: test1.yml
            #src: /root/index.html
            dest: /root/user13.yml
            #dest: /var/www/html
            owner: apache
            group: apache
            mode: 0644
          tags: haha
          notify:
            - restart httpd
            - restart vsftpd
            - modify port
      handlers:
        - name: modify port
          replace:
            path: /etc/httpd/conf/httpd.conf
            regexp: '(^Listen ).*'
            replace: '1 80'
            backup: yes
        - name: restart httpd
          service: name=httpd state=restarted
        - name: restart vsftpd
          service: name=vsftpd state=restarted
        - service:
            name: httpd
            state: restarted
            enabled: yes

    注意格式要求,一般的copy,replace,yum,sevice模块用ansible-doc 模块名  查看帮助就ok

  • 相关阅读:
    hdu 1002 A + B Problem II
    hdu 1001 Sum Problem
    hdu 1000 A + B Problem
    mysql允许其他电脑访问权限开通
    zend studio安装svn插件
    phpcms采集地址中为相对路径解决方法
    如何解决phpcms后台验证码不显示的问题
    phpcms常用方法简介
    网站标签栏ico设置代码
    phpcms get标签用法
  • 原文地址:https://www.cnblogs.com/lsgo/p/10422576.html
Copyright © 2011-2022 走看看