CSDN-DATA2-ARCHITECTURE-ansible1

1 简述什么是ansible
ansible是2013年推出的一款IT自动化和DevOps软件,2015年被RedHat收购。是基于Python研发,糅合很多老运维工具的优点,实现了批量操作系统配置,批量程序部署,批量运行命令等功能
2 ansible可以实现什么功能
自动化部署APP
自动化管理配置项
自动化持续交付
自动化(AWS)云服务管理
3 ansible优点有哪些
只需要SSH和Python即可使用,无客户端
ansible功能强大,模块丰富
上手容易,门槛低
基于Python开发,做二次开发更容易
使用公司比较多,社区活跃
4 简述ansible中主机定义与分组的步骤
1、ansible.cfg 配置文件:
inventory定义托管主机地址配置文件
2、编辑/etc/ansible/hosts文件,写入远程主机的地址。
格式:
[组名称]
主机名称或ip地址,登录用户名,密码、端口等信息
测试:
ansible [组名称] --list-hosts
定义主机分组练习
[root@ansible ~]# cd /etc/ansible/
[root@ansible ansible]# ls
ansible.cfg hosts roles
[root@ansible ansible]# vim ansible.cfg
#inventory = /etc/ansible/hosts //指定分组文件路径,主机的分组文件hosts
[selinux] //组名称,selinux的相关选项在这个下面配置

[colors] //组名称,colors的相关选项在这个下面配置

[root@ansible ansible]# vim hosts
[web]
web1
web2
[root@ansible ansible]# ansible web --list-host //显示web组的主机
hosts (2):
web1
web2
5 如何用ansible批量部署证书文件,给所有主机部署密钥
1)创建密钥
[root@ansible aaa]# cd /root/.ssh/
[root@ansible .ssh]# vi /etc/ansible/hosts
[web]
web1
web2
[db]
db[1:2]
[other]
cache
[root@ansible .ssh]# ansible all -m ping //直接ping会报错
[root@ansible .ssh]# ssh-keygen -t rsa -b 2048 -N ‘’ //创建密钥
2)给所有主机部署密钥
[root@ansible .ssh]# ansible all -m authorized_key -a “user=root exclusive=true manage_dir=true key=’$(< /root/.ssh/id_rsa.pub)’” -k
SSH password: //输入密码
[root@ansible .ssh]# ansible all -m ping //成功
web2 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
db2 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
web1 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
cache | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
db1 | SUCCESS => {
“changed”: false,
“ping”: “pong”
}
[root@ansible .ssh]# ssh web1 //不需要输入密码,可以直接登陆
Last login: Thu Sep 6 11:49:00 2018 from 192.168.1.51

猜你喜欢

转载自blog.csdn.net/weixin_42976488/article/details/83855823
今日推荐