ansible.cfg文件及host文件配置

简介:

ansible.cfg文件及host文件配置


inventory:资源清单文件的存放,资源清单就是一些主机的列表。可以指向一个文件也可以指向一个目录。

默认为:

1
inventory      =  /etc/ansible/hosts


library:ansible的操作动作,指定ansible模块的目录。

默认为:

1
library        =  /usr/share/my_modules/



forks:设置ansible最多能有多少个进程同时工作。

默认为:

1
forks          = 5



sudo_user:默认执行命令的用户,可以在playbook中重新设置这个参数。

默认为:

1
#sudo_user      = root



remote_port:远程被管节点的管理关口,默认为22.


host_key_checking:设置是否检查ssh主机的秘钥。

1
默认为:host_key_checking = False



timeout:设置ssh连接超时的时间间隔。

默认为:

1
timeout = 10

log_path:指定ansible执行过程存储日志的文件。

1
log_path =  /var/log/ansible .log


host文件的配置:


可以这样写:

1
2
3
[ test ]
192.168.121.128
192.168.121.129



也可以这样写:

1
2
[ test ]
192.168.121.[128:129]


1
2
3
# ansible test -m 'ping ' -o
192.168.121.128 | SUCCESS => { "changed" false "ping" "pong" }
192.168.121.129 | SUCCESS => { "changed" false "ping" "pong" }



要是host主机分组比较多,都属于同一个大组,不同的小组,可以这样写:


1
2
3
4
5
6
7
[ test :children]
test1
test2
[test1]
192.168.121.128
[test2]
192.168.121.129



1
2
3
4
5
6
7
[root@192 ansible] # ansible test -m 'ping ' -o
192.168.121.128 | SUCCESS => { "changed" false "ping" "pong" }
192.168.121.129 | SUCCESS => { "changed" false "ping" "pong" }
[root@192 ansible] # ansible test1 -m 'ping ' -o
192.168.121.128 | SUCCESS => { "changed" false "ping" "pong" }
[root@192 ansible] # ansible test2 -m 'ping ' -o
192.168.121.129 | SUCCESS => { "changed" false "ping" "pong" }

当然也可以查看这个组下的主机:

[

1
2
3
4
5
6
7
root@192 ansible] # ansible test1 --list-hosts
   hosts (1):
     192.168.121.128
[root@192 ansible] # ansible test --list-hosts
   hosts (2):
     192.168.121.128
     192.168.121.129



本文转自青衫解衣 51CTO博客,原文链接:http://blog.51cto.com/215687833/1886319
相关文章
「译文」如何在 Ansible 中复制多个文件和目录
「译文」如何在 Ansible 中复制多个文件和目录
|
11月前
|
运维 Kubernetes 网络安全
Ansible自动化运维工具之主机管理与自定义配置文件(2)
Ansible自动化运维工具之主机管理与自定义配置文件(2)
125 0
|
19天前
|
运维 应用服务中间件 nginx
自动化运维的利剑:Ansible Role 打造标准化配置
【8月更文挑战第31天】在追求效率和稳定性的今天,自动化运维不再是奢侈品,而是必需品。Ansible Role,作为自动化配置管理的利器,它如何帮助我们实现标准化部署和维护?本文将通过一个简单示例,带你了解 Ansible Role 的魅力所在,并探讨其在现代 IT 架构中的应用价值。
|
2月前
|
安全 Devops KVM
Ansible的基本配置
Ansible的基本配置
36 2
|
1月前
|
JSON 运维 Linux
在CentOS 7上安装和配置Ansible的方法
在CentOS 7上安装和配置Ansible的方法
54 0
|
4月前
|
运维 关系型数据库 MySQL
Ansible自动化运维工具主机清单配置
Ansible自动化运维工具主机清单配置
116 0
|
11月前
|
Kubernetes Linux 持续交付
在 Alibaba Cloud Linux 上搭建并配置 Ansible
本场景简单介绍了在Alibaba Cloud Linux上安装并配置Ansible的方式。
|
Linux 网络安全 数据安全/隐私保护
在 Alibaba Cloud Linux 上配置 Ansible
本场景是在 Alibaba Cloud Linux 上配置 Ansible
240 0
|
网络协议 网络安全 数据安全/隐私保护
Ansible模块介绍——配置网络模块、上传下载文件模块
Ansible模块介绍——配置网络模块、上传下载文件模块
354 0
【初始环境】ansible配置/免密登录配置
文章目录 前言 一、ansible 二、结语
333 0