# 在线yum安装
代码语言:javascript复制[root@summer ~]# yum install -y epel-release ##先安装epel源
[root@summer ~]# yum install ansible -y
[root@summer ~]# ansible --version
ansible 2.9.15
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Apr 2 2020, 13:16:51) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]
[root@summer ~]#
# 离线安装
略
思路是yum获取所有的依赖包
# 配置免密登录
- host配置
[root@summer ~]# vim /etc/ansible/host
[redis]
192.168.0.68 ansible_ssh_user=root ansible_ssh_pass=hadoop prot=27000
192.168.0.186 ansible_ssh_user=root ansible_ssh_pass=1340904087 prot=27000
192.168.0.90 ansible_ssh_user=root ansible_ssh_pass=1340904087 prot=27000
...
- 免密互信
这里注意添加本机ip
代码语言:javascript复制[root@summer ~]# ssh-keygen -t rsa
[root@summer ~]# ssh-copy-id 192.168.0.68
[root@summer ~]# ssh-copy-id 192.168.0.90
[root@summer ~]# ssh-copy-id 192.168.0.186
- 验证
- 列出所有被管理主机list
ansible all --list
- ping各节点
ansible all -m ping
- 查看hostname
ansible summer -m shell -a 'hostname' -o
- 查看主机内存信息
ansible all -m setup -a 'filter=ansible_*_mb'
- 创建文件夹
ansible summer -m file -a 'path=/home/app state=directory'
- 查看文件
ansible summer -m shell -a 'ls -l /home/app'
- 删除文件
ansible summer -m file -a 'path=/home/app state=absent'
- 复制文件到本机
ansible summer -m fetch -a 'src=/home/app/123.txt dest=/home'