Ansible是一种自动化的运维工具,基于Python开发,它集合了众多运维工具(比如puppet、chef、func等)的优点,能够实现批量操作。但其实Ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是Ansible所运行的模块,Ansible只是提供一种框架
yum install epel-release
yum repolist
yum install -y ansible
#修改如下文件,新增定义Ansible模块
vi /etc/ansible/hosts
# 接下来定义Ansible模块
# ansible_ssh_port 连接目标远程主机的端口
# ansible_ssh_user 连接目标远程主机默认用户
# ansible_ssh_pass 连接目标远程主机默认用户密码
[bdp:children]
master
slaves
[bdp:vars]
ansible_ssh_port=22
#ansible_ssh_user=root
#ansible_ssh_pass='gis@bdp'
ansible_ssh_user=hadoop
ansible_ssh_pass='gis@hadoop'
[master:children]
m_master
s_master
[m_master]
192.168.254.121
[s_master]
192.168.254.122
[slaves:children]
dn
web
[dn]
192.168.254.123
192.168.254.124
192.168.254.125
[web]
192.168.254.126
# 修改该文件中 host_key_checking = False (避免SSH_KEY问题)
vi /etc/ansible/ansible.cfg
host_key_checking = False
# 基于passlib生成密码 假设加密后的值为 xxx
python -c 'import crypt; print (crypt.crypt("password","hadoop"))'
# 添加组
ansible bdp -m group -a 'name=hadoop gid=666 state=present system=yes'
# 添加用户到指定组
ansible bdp -m user -a 'name=hadoop password=haN6/RvMI9uPo update_password=always shell=/bin/bash group=hadoop state=present system=yes createhome=yes home=/home/hadoop'
# 删除用户
ansible bdp -m user -a "name=hadoop state=absent"