Ansible基础知识

作者: 如来自然 | 来源:发表于2016-01-15 21:49 被阅读98次

首先我们看下ansible的配置文件(有删减):

[root@www ~]# cat /etc/ansible/hosts

Ex 1: Ungrouped hosts, specify before any group headers.

下面是没有分组的主机,可以写域名、ip、别名。

www .fuchao.com #域名
alias01 ansible_ssh_port=22 ansible_ssh_host =192.168.1.144 #别名 alias01
192.168.1.144 #ip

192.168.1.145

Ex 2: A collection of hosts belonging to the 'webservers' group

一组主机属于“网路”组

[webservers] #组名 ,下面的成员可以用域名、ip、别名。
www.fuchao.com #组员域名
192.168.1.144 #组员ip
192.168.1.145

If you have multiple hosts following a pattern you can specify

如果你有多个主机后,您可以指定一个模式

them like this:#他们是这样的

www[001:006].example.com #支持正则,假如你有一万台主机 ,而且很有规则。

www[1:10000].example.com #假如你有一万台主机 ,而且很有规则

Ex 3: A collection of database servers in the 'dbservers' group

一个集合的数据库服务器“dbservers”组

[dbservers] #组名

db01.intranet.mydomain.net
db02.intranet.mydomain.net
10.25.1.56
10.25.1.57

Here's another example of host ranges, this time there are no

leading 0s:

db-[99:101]-node.example.com

[root@www ~]#

定义主机变量:

为了方便让playbooks配置使用。

[Hvariables]

host1 http_port=80
host2 http_port=8080

定义组变量:

组变量作用于组的所有成员

[Gvariable]
host1
host2
[Gvariable:vars]
ftp_server = ftp.fuchao.com
web_server = www.fuchao.com

目标匹配:

ansible <pattern_goes_here> -m <module_name> -a <argumrnts>

匹配目标地址或主机地址: 用冒号(:)分隔开。

匹配组 : 用冒号(:)分隔开。

匹配所有主机 : ALL 或者星号(*)

支持正则表达方式匹配主机或者ip

匹配 一个组除某个ip的所有成员 :组名:!ip

匹配两个组织间的交集:组1:&组2

相关文章

  • ansible基础知识

    一、ansible简介 1、ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(pu...

  • Ansible基础知识

    Ansible主配置文件:/etc/ansible/ansible.cfgInventory配置文件:/etc/a...

  • Ansible基础知识

    首先我们看下ansible的配置文件(有删减): [root@www ~]# cat /etc/ansible/h...

  • 【Ansible学习】- Ansible初探

    安装 Ansible基础 Ansible架构图 Ansible核心组件说明 Ansible:Ansible的核心程...

  • 快速上手 Ansible

    Ansible 系列:(一):快速上手 Ansible(二):Ansible 命令(三):Ansible 主机清单...

  • Ansible 命令

    Ansible 系列:(一):快速上手 Ansible(二):Ansible 命令(三):Ansible 主机清单...

  • Ansible 主机清单配置文件

    Ansible 系列:(一):快速上手 Ansible(二):Ansible 命令(三):Ansible 主机清单...

  • Ansible Playbook 剧本语法

    Ansible 系列:(一):快速上手 Ansible(二):Ansible 命令(三):Ansible 主机清单...

  • Ansible(一)、实现SSH免密

    1.ansible安装 2.ansible配置 /etc/ansible/ansible.cfg /etc/ans...

  • Ansible第一篇:基础

    一、配置文件 ansible.cfg /etc/ansible/ansible.cfg 是ansible安装好后...

网友评论

    本文标题:Ansible基础知识

    本文链接:https://www.haomeiwen.com/subject/armhkttx.html