ansible-playbook批量安装httpd

安装ansible

 [root@ansible ~]#yum install ansible 

 

编写ansible主机清单:

[root@ansible ansible]# cat /etc/ansible/hosts 

[centos8]
192.168.18.130
192.168.18.132

 

编写playbook实现批量安装httpd

[root@ansible ansible]# vim install-httpd.yml 
---
- hosts: centos8
  gather_facts: yes

  tasks:
          - name: Install httpd
            yum: name=httpd state=present
          - name: create group
            group: name=apache gid=80 system=yes
          - name: create user
            user: name=apache uid=80 group=apache shell=/sbin/nologin
          - name: Install configure file
            copy: content="welcome {{ ansible_nodename }} \n" dest=/var/www/html/index.html
          - name: modify config
            lineinfile: path=/etc/httpd/conf/httpd.conf regexp='^Listen' line='Listen 8080'
          - name: start service
            service: name=httpd state=started enabled=yes

 

执行playbook


[root@ansible ansible]# ansible-playbook install-httpd.yml 

 

测试验证

[root@ansible ansible]# curl 192.168.18.130:8080
welcome slave1 
[root@ansible ansible]# curl 192.168.18.132:8080
welcome slave2

 

上一篇:Ansible基本使用(上)


下一篇:ansible playbook使用