ansible之playbook

一键基础环境部署脚本

---
- hosts: commons
tasks:
- name: Bash environment install
yum: name={{ item }} state=present
with_items:
- gcc
- gcc-c++
- gdb
- readline-devel
- bind-utils
- lsof
- dos2unix
- mtr
- hdparm
- iptables-services
- sysstat
- wireshark
- openssl
- openssl-devel
- nload
- perl
- perl-devel
- perl-ExtUtils-Embed
- nmap
- ipset
- telnet

- file:
path: /root/jb
state: directory
mode: 755

- file:
path: /tmp/trash
state: directory
mode: 755

- copy:
src: "/etc/ansible/modules/jb/iptables.sh"
dest: "/root/jb/iptables.sh"

- copy:
src: /etc/ansible/modules/jb/trashclean.py
dest: /root/jb/trashclean.py
mode: o+x

- cron:
name: Clean trash
minute: "1"
hour: "23"
day: "1"
job: "/root/jb/trashclean.py"

- unarchive:
src: /etc/ansible/modules/jb/Python-3.5.2.tgz
dest: /root/jb

- name: About Python3
command: /root/jb/Python-3.5.2/configure
args:
chdir: /root/jb/Python-3.5.2

- name: About Python3
command: /usr/bin/make
args:
chdir: /root/jb/Python-3.5.2

- name: About Python3
command: /usr/bin/make install
args:
chdir: /root/jb/Python-3.5.2

- lineinfile:
path: /etc/bashrc
line: 'alias rm="mv --verbose -f --backup=numbered --target-directory /tmp/trash"'

- lineinfile:
path: /etc/profile
line: 'export HISTFILESIZE=1000000'

- lineinfile:
path: /etc/profile
line: 'export HISTSIZE=10000'

- lineinfile:
path: /etc/profile
line: 'export PROMPT_COMMAND="history -a"'

- lineinfile:
path: /etc/profile
line: 'export HISTTIMEFORMAT="`whoami`_%F %T : "'

- name: About account
command: useradd yunwei

- name: Stop firewall
command: systemctl stop firewalld.service

- name: Start iptables
command: systemctl enable iptables

- name: Set blackip
command: ipset create blackip hash:ip maxelem 1000000

- name: Reboot server
shell: /usr/sbin/reboot

 END!

原文地址:https://www.cnblogs.com/changbo/p/7382563.html