ansible-playbook 批量部署httpd服务

cat etc/ansible/hosts
[web]
192.168.200.10
[web:vars]
ansible_ssh_user=root
ansible_ssh_pass=‘123456’

ls /etc/ansible/
https.yaml
httpd.conf.j2
index.html

cat /etc/ansbile/httpd.yaml

---
  - hosts: web
      tasks:
        - name: download apr apr-util httpd
          get_url: url={{item}} dest=/root/gpk timeout=60
          with_items:
            - http://mirrors.ustc.edu.cn/apache/apr/apr-1.6.5.tar.gz
	        - http://mirrors.ustc.edu.cn/apache/apr/apr-util-1.6.1.tar.gz
	        - http://mirrors.ustc.edu.cn/apache/httpd/httpd-2.4.39.tar.gz
          delegate_to: localhost
          run_once: True
        - name: install pcre pcre-devel
          yum: name: {{item}} state=present
          with_items:
            - pcre
            - pcre-devel
            - expat-devel #编译apr-util 会出错,安装此包解决
        - name: unarchive apr apr-util httpd
          unarchive: src=/root/gpk/{{item}} dest=/root/ copy=yes
          with_items:
            - apr-1.6.5.tar.gz
            - apr-util-1.6.1.tar.gz
            - httpd-2.4.39.tar.gz
          tags: unarchive
         - name: complie apr
           shell: |
             cd /root/apr-1.6.5
             ./configure --prefix=/usr/local/apr
             make && make install
           tags: apr
         - name: complie apr-util
            shell: |
              cd apr-util-1.6.1
              ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
              make && make install
            tags: apr-util
         - name: complie httpd
           shell: |
             cd httpd-2.4.39
             ./configure --prefix=/usr/local/apache --sysconfdir=/etc/apache/ \
                     --enable-mpms-shared=all \
                     --with-z --with-pcre \
                     --with-apr=/usr/local/apr \
                     --with-apr-util=/usr/local/apr-util \
                     --with-mpm=event
              make && make install
            tags: httpd  
          - name: copy http.conf index.html
            tempale: |
              src=http.conf.j2 dest=/etc/apache/httpd.conf
              src=index.html dest=/usr/local/apache/htdocs/index.html
          - name: start httpd
            shell: /usr/local/apache/bin/apachectl start
            
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值