ansible 安装

  • 服务端要求

     Python 2.6+

     RedHat Debian CentOS  OSX 等

    不支持Windows

  • 被管理端要求

     OpenSSH

     Python 2.6+

 

  • #安装

yum install -y ansible -y

#pip  install -y ansible

#https://github.com/ansible/ansible.git

vim /etc/ansible/hosts

#配置管理IP段

[webservers]

192.168.10.251 ansible_ssh_user=root ansible_ssh_pass=123.com
192.168.10.252 ansible_ssh_user=root ansible_ssh_pass=123.com
192.168.10.253 ansible_ssh_user=root ansible_ssh_pass=123.com

#测试联通

[root@k8s-master01 tmp]# ansible webservers -a "df -h"
192.168.10.251 | SUCCESS | rc=0 >>
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   37G   20G   18G  53% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  393M  3.5G  11% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  142M  873M  14% /boot
tmpfs                    3.9G   12K  3.9G   1% /var/lib/kubelet/pods/aee9f414-54e8-47f7-ab4c-ad7a8a6884b1/volumes/kubernetes.io~secret/flannel-token-k7wbl
tmpfs                    783M     0  783M   0% /run/user/0

192.168.10.253 | SUCCESS | rc=0 >>
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   37G   19G   19G  49% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  131M  3.7G   4% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  142M  873M  14% /boot
tmpfs                    783M     0  783M   0% /run/user/0

192.168.10.252 | SUCCESS | rc=0 >>
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   37G   32G  5.7G  85% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  393M  3.5G  11% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1               1014M  142M  873M  14% /boot
tmpfs                    783M     0  783M   0% /run/user/0
tmpfs                    3.9G   12K  3.9G   1% /var/lib/kubelet/pods/214bcf7f-5703-4b1d-8049-7e8c5ba13382/volumes/kubernetes.io~secret/flannel-token-k7wbl

#查看内存

ansible webservers -a "free -m"

  • #基本配置

vim /etc/ansible/ansible.cfg

[defaults]

inventory      = /etc/ansible/hosts
forks          = 5
sudo_user      = root
remote_port    = 22
host_key_checking = False
timeout         = 10
log_path        = /var/log/ansible.log
private_key_file = /root/.ssh/id_rsa

  • Inventory 主机清单

/etc/ansible/hosts 中默认给提供了三种模板

Ex1:未分组的主机,默认在all组中。

ansible all -a "free -m"

Ex2:属于webservers的主机组。

           ansible webservers -a "free -m"

          主机名称有规律可以使用范围配置

Ex3:属于dbservers的主机组。

#IP 连接IP  ssh用户  密码

[webservers]

192.168.10.251 ansible_ssh_user=root ansible_ssh_pass=123.com
192.168.10.252 ansible_ssh_user=root ansible_ssh_pass=123.com
192.168.10.253 ansible_ssh_user=root ansible_ssh_pass=123.com

#定义变量

#https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html

vim /etc/ansible/group_vars/webservers.yml 

http_port: 8080
server_name: www.baidu.com

ansible webservers  -a "echo {{http_port}}"

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值