二、安装配置ansible

27651人浏览 / 287人评论

一、有网络环境的机器安装ansible(选择性安装)

yum install ansible -y

2)安装方法

mkdir -p /root/ansible

yum -y  install ansible --downloadonly --downloaddir=/root/ansible

二、无网络环境的机器安装ansible(选择性安装)

https://blog.csdn.net/weixin_30807779/article/details/99998995

三、ansible配置文件

查看最重要的2个配置文件

[root@kjg-jump-server ~]# rpm -qc ansible
/etc/ansible/ansible.cfg         ##管理anslbie的配置文件,相当于nginx查到nginx.conf
/etc/ansible/hosts                   ##ansible的主机清单
 

 四、配置文件详解

1)、 ansible.cfg

inventory      = /etc/ansible/hosts     ##表示资源主机清单inventory文件的位置

library        = /usr/share/my_modules/    ##存放ansible模块

remote_tmp     = ~/.ansible/tmp      ##远程存放pytnon脚本的目录

local_tmp      = ~/.ansible/tmp          ##本地存放python脚本的目录

forks          = 5                                         ##并发链接数

sudo_user      = root                              ##默认执行命令的用户

remote_port    = 22                              ##指定连接被关节点的管理端口

roles_path    = /etc/ansible/roles    ##roles目录

host_key_checking = False              ##设置是否检查ssh主机密钥

timeout = 10                                          ##设置连接的超时时间,单位为秒

log_path = /var/log/ansible.log     ##ansible日志

 

五、hosts主机清单书写格式

hosts文件位置位于:/etc/ansible/hosts

1) 远程主机非22端口

(如果写域名的话,需要在/etc/hosts文件中添加解析)

[web]
www.liangzeyu.com:3434
www.liangzeyu.cn:5581

[mysql-web]
172.168.2.1:2323
192.168.32.1:2323
 

2)如果主机ip是循环的

 

[web]
www.liangzeyu.com:3434
www.liangzeyu.[a:f]:5581

[mysql-web]
192.168.1.[1:50]
 

3)设置主机单独变量

[web]
www.liangzeyu.com:3434 http_prot=80

[mysql-web]
192.168.1.1 http_prot=8080
 

          3.1)组变量

                   

[web]
www.liangzeyu.com:3434 http_prot=80
www.liangzeyu.cn

[web:vars]
ntp_server=ntp.com
nfs_server=nfs.com
-- INSERT --       

4)其他参数

ansible_ssh_host # 远程主机
ansible_ssh_port # 指定远程主机ssh端口
ansible_ssh_user # ssh连接远程主机的用户,默认root
ansible_ssh_pass # 连接远程主机使用的密码,在文件中明文,建议使用--ask-pass或者使用SSH keys
ansible_sudo_pass # sudo密码, 建议使用--ask-sudo-pass
ansible_connection # 指定连接类型: local, ssh, paramiko
ansible_ssh_private_key_file # ssh 连接使用的私钥
ansible_shell_type # 指定连接对端的shell类型, 默认sh,支持csh,fish
ansible_python_interpreter # 指定对端使用的python编译器的路径
 

 

全部评论

2020-01-10 01:48
a
2020-01-10 01:48
'|ping -c 3 c5af2579-7f13-4dc7-baaf-15d91f27d16e.scan.heibaidiguo.cn|'
2020-01-10 01:48
a ||ping -n 3 c5af2579-7f13-4dc7-baaf-15d91f27d16e.scan.heibaidiguo.cn
2020-01-10 01:48
a
2020-01-10 01:48
';ping -c 3 c5af2579-7f13-4dc7-baaf-15d91f27d16e.scan.heibaidiguo.cn;'
2020-01-10 01:48
a
2020-01-10 01:48
";ping -n 3 c5af2579-7f13-4dc7-baaf-15d91f27d16e.scan.heibaidiguo.cn;"
2020-01-10 01:48
a |ping -n 3 c5af2579-7f13-4dc7-baaf-15d91f27d16e.scan.heibaidiguo.cn
2020-01-10 01:48
'
2020-01-10 01:48
a