> 文章列表 > ansible自动运维——看明白ansible.cfg配置文件

ansible自动运维——看明白ansible.cfg配置文件

ansible自动运维——看明白ansible.cfg配置文件

 大家好,这里是天亮之前ict,本人网络工程大三在读小学生,拥有锐捷的ie和红帽的ce认证,这里我会定期跟新自动话运维的博客,希望能提高自己的技术的同时,也可以帮助到大家,另外大家可以关注我的其它专栏:

锐捷数通实验:锐捷数通实验

网络工程师成长日志:网络工程师成长日志

linux命令每日分享: linux命令每日分享

     要想ansible能运行出来,ansible的配置文件一定要看明白,这关乎着你是否有能给客户端下达任务的资格,ansible.cfg文件比较庞大,但是有几个必备的参数是一定要整好的,本篇博客就介绍一下ansible.cfg里面重要的参数。

目录

一、ansible的配置文件说明

二、ansible.cfg配置说明

2.1常用配置参数

 2.2实战演示

一、ansible的配置文件说明

从ansible --version可以看出来,ansibled的主要配置文件在/etc/ansible/ansible.cfg

 该目录下还有如下目录:

 这就是一个ansible的主配置文件,但是我们不经常直接用这些,因为这些东西的权限都是root,我们不如把这些拷贝到家目录下:

[student@workstation etc]$ cd /home/student/
[student@workstation ~]$ mkdir -p ansible
[student@workstation ~]$ cd ansible/
[student@workstation ansible]$ cp /etc/ansible/ansible.cfg .
[student@workstation ansible]$ ll -a
total 20
drwxrwxr-x. 2 student student    25 Dec 31 15:25 .
drwx------. 6 student student   158 Dec 31 15:25 ..
-rw-r--r--. 1 student student 19985 Dec 31 15:25 ansible.cfg

这样属主和属组就变成了你的用户

二、ansible.cfg配置说明

2.1常用配置参数

注: 标红部分为特别注意选项
#[default]                ##基本信息设定
inventory=              ##指定清单路径,invenstry=/etc/ansible/hosts,hosts中存放各种主机信息
remote_user=        ##在受管主机上登陆的用户名称,未指定使用当前用户
ask_pass=             ##是否提示输入SSH密码,如果公钥登陆设定为false,false的话不用输入密码,true的话就要输入ssh的密码
library=                  ##库文件存放目录
local_tmp=            ##本机临时命令执行目录
remote_tmp=         ##远程主机临时py命令文件存放目录
forks=                    ##默认并发数量
host_key_checking=         ##第一次连接受管主机时是否要输入yes建立host_key,如果这里不输入False,那么第一次连接客户端的时候会弹一屏幕的东西,你懂的
sudo_user=                ##默认sudo用户
ask_sudo_pass=              ##每次在受控主机执行ansible命令时是否询问sudo密码
module_name=                ##默认模块,默认使用command,可以修改为shell
log_path=                         ##日志文件路径

[privilege_escalation]
become                  =True
become_method           =sudo    ##切换用户的方式为sudo
become_user             =root
become_ask_pass         =False   ##做sudo的时候是否提示输入密码,最好false

 2.2实战演示

  通过grep -v -e '#' -e '^$' ansible.cfg 查看我们的配置文件

[student@workstation ansible]$ grep -v -e '#' -e '^$' ansible.cfg 
[defaults]
inventory      = /home/student/ansible/inventory
ask_pass      = False
roles_path    = /home/student/ansible/roles
remote_user = student
[inventory]
[privilege_escalation]
become=True
become_method=sudo
become_user=root
become_ask_pass=False
[paramiko_connection]
[ssh_connection]
[persistent_connection]
[accelerate]
[selinux]
[colors]
[diff]
[student@workstation ansible]$ 

 “生活的方向无论你如何选择都会后悔,人总向往没经历过的生活”