Ansiable bulk configuration management through playbook
playbook is composed of one or more modules. It uses many different modules to accomplish one thing.
Install a service, configure, and start.
1. Find someone to shoot.
2. General tasks.
3. How to do it.
Install httpd Service - > Playbook
1. installation
2. configuration
3. boot
[root@m01 ~]# cat httpd_install.yaml - hosts: web tasks: - name: Install Httpd Server yum: name=httpd,httpd-tools state=installed - name: Configure Httpd Server copy: src=./httpd.conf dest=/etc/httpd/conf/httpd.conf - name: Start Httpd Server service: name=httpd state=started enabled=yes
2. Modify the locally copied httpd.conf file
3. Execute ansible playbook httpd [install.yaml push
Batch management initialization cluster
1. Environmental planning
role | Internet IP(NAT) | Intranet IP(LAN) | Deployment Software |
---|---|---|---|
m01 | eth0:10.0.0.61 | eth1:172.16.1.61 | ansible |
backup | eth0:10.0.0.41 | eth1:172.16.1.41 | rsync |
nfs | eth0:10.0.0.31 | eth1:172.16.1.31 | nfs,Sersync |
web01 | eth0:10.0.0.7 | eth1:172.16.1.7 | httpd |
Achieve goals
- Full network backup
- Real time backup
Directory planning
[root@m01 ~]# mkdir /etc/ansible/ansible_playbook/{file,conf,scripts} -p [root@m01 ~]# tree /etc/ansible/ansible_playbook/ /etc/ansible/ansible_playbook/ ├── conf └── file └── scripts
Basic environment: unified configuration of all machines
1. You need to close firewalld, selinux, epel warehouse, ssh port and optimize basic configuration
2. rsync and NFS utils need to be installed
3. Prepare for www users
4. You need to prepare the / etc/rsync.pass password file
5. Need to prepare the whole network backup script
1. Basic playbook script
[root@m01 ansible_playbook]# cat base.yaml - hosts: all tasks: - name: Install Epel Repos get_url: url=http://mirrors.aliyun.com/repo/epel-7.repo dest=/etc/yum.repos.d/epel.repo - name: Dns Client copy: src=./conf/resolv.conf dest=/etc/resolv.conf - name: Install Rsync Nfs-Utils yum: name=rsync,nfs-utils state=installed - name: Create Group WWW group: name=www gid=666 - name: Create User WWW user: name=www uid=666 group=666 create_home=no shell=/sbin/nologin - name: Create Rsync_Client_Pass copy: content='1' dest=/etc/rsync.pass mode=600 - name: Create Scripts Directory file: path=/server/scripts recurse=yes state=directory - name: Push File Scripts copy: src=./scripts/rsync_backup_md5.sh dest=/server/scripts/ - name: Crontable Scripts cron: name="backup scripts" hour=01 minute=00 job="/bin/bash /server/scripts/rsync_backup_md5.sh &>/dev/null"
2. Application environment: Rsync
1. Install rsync
2. Configure rsync
3. Create virtual users and adjust permissions
4. Create directory / data / backup
5. Start rsync
6. Configure mailbox - > sender of mailbox - > script for verification
[root@m01 ansible_playbook]# cat rsync.yaml - hosts: backup tasks: - name: Installed Rsync Server yum: name=rsync,mailx state=installed - name: configure Rsync Server copy: src=./conf/rsyncd.conf dest=/etc/rsyncd.conf notify: Restart Rsync Server - name: Create Virt User copy: content='rsync_backup:1' dest=/etc/rsync.password mode=600 - name: Create Data file: path=/data state=directory recurse=yes owner=www group=www mode=755 - name: Create Backup file: path=/backup state=directory recurse=yes owner=www group=www mode=755 - name: Start RsyncServer service: name=rsyncd state=started enabled=yes - name: Push Check Scripts copy: src=./scripts/rsync_check_backup.sh dest=/server/scripts/ - name: Crond Check Scripts cron: name="check scripts" hour=05 minute=00 job="/bin/bash /server/scripts/rsync_check_backup.sh &>/dev/null" handlers: - name: Restart Rsync Server service: name=rsyncd state=restarted
3. Application environment: NFS
1. Install NFS utils
2. Configure nfs (when the configuration is modified, overload operation will be triggered)
3. Create directory, authorize
4. boot
[root@m01 ansible_playbook]# cat nfs.yaml - hosts: nfs tasks: - name: Installed Nfs Server yum: name=nfs-utils state=installed - name: Configure Nfs Server copy: src=./conf/exports dest=/etc/exports notify: Restart Nfs Server - name: Create Share Data file: path=/data state=directory recurse=yes owner=www group=www mode=755 - name: Start Nfs Server service: name=nfs-server state=started enabled=yes handlers: - name: Restart Nfs Server service: name=nfs-server state=restarted
4. Application environment: Sersync
1. Download sersync
2. Unzip, rename and configure
3. boot
[root@m01 ansible_playbook]# cat sersync.yaml - hosts: nfs tasks: - name: Scp Sersync copy: src=./file/sersync2.5.4_64bit_binary_stable_final.tar.gz dest=/usr/local/sersync.tar.gz - name: Zip shell: cd /usr/local && tar xf sersync.tar.gz && mv GNU-Linux-x86 sersync args: creates: /usr/local/sersync - name: configure Sersync copy: src=./conf/confxml.xml dest=/usr/local/sersync/ - name: Start Sersync shell: /usr/local/sersync/sersync2 -dro /usr/local/sersync/confxml.xml
5. Application environment: WEB
1. Mount the directory of the nfs share
[root@m01 ansible_playbook]# cat web.yaml - hosts: web tasks: - name: Mount NFS Server Share Data mount: src=172.16.1.31:/data path=/data fstype=nfs opts=defaults state=mounted
6. Overall call through import ﹣ Playbook
[root@m01 ansible_playbook]# cat mail.yaml - import_playbook: base.yaml - import_playbook: rsync.yaml - import_playbook: nfs.yaml - import_playbook: sersync.yaml - import_playbook: web.yaml