首页 > 其他分享 >ansible使用手册

ansible使用手册

时间:2024-07-05 13:54:17浏览次数:16  
标签:staging webservers host ansible hosts inventory 使用手册

Connection methods and details — Ansible Community Documentation

1 build your inventory

1.1

The default location for this file is /etc/ansible/hosts. You can specify a different inventory file at the command line using the -i <path> option or in configuration using inventory.

mkdir -p /ansible_quickstart
# 建立一个ini格式的inventory
touch inventory.ini
cat inventory.ini
[myhosts]
172.31.18.222

# 或者创建一个yaml格式的inventory
touch inventory.yaml
cat inventory.yaml
myhosts:
hosts:
  my_host_01:
    ansible_host: 172.31.18.222

1.2 Passing multiple inventory sources

ansible-playbook get_logs.yml -i staging -i production

1.3 Inventory aliases

In ini format

jumper ansible_port=5555 ansible_host=192.0.2.50

In yaml format

# ...
hosts:
  jumper:
    ansible_port: 5555
    ansible_host: 192.0.2.50
 

2 Patterns: targeting hosts and groups

2.1 Using patterns

ansible <pattern> -m <module_name> -a "<module options>"
例子
ansible webservers -m service -a "name=httpd state=restarted"

In a playbook, the pattern is the content of the hosts: line for each play:

- name: <play_name>
hosts: <pattern>
 
例子
- name: restart webservers
hosts: webservers

 

2.2 常见模式

DescriptionPattern(s)Targets
All hosts all (or *)  
One host host1  
Multiple hosts host1:host2 (or host1,host2)  
One group webservers  
Multiple groups webservers:dbservers all hosts in webservers plus all hosts in dbservers
Excluding groups webservers:!atlanta all hosts in webservers except those in atlanta
Intersection of groups webservers:&staging any hosts in webservers that are also in staging

例子

webservers:dbservers:&staging:!phoenix

targets all machines in the groups ‘webservers’ and ‘dbservers’ that are also in the group ‘staging’, except for any machines in the group ‘phoenix’.

 

 

 

标签:staging,webservers,host,ansible,hosts,inventory,使用手册
From: https://www.cnblogs.com/goldtree358/p/18285659

相关文章

  • Ansible 最佳实践:现代 IT 运维的利器
    Ansible最佳实践:现代IT运维的利器Ansible是一种开源的IT自动化工具,通过SSH协议实现远程节点和管理节点之间的通信,适用于配置管理、应用程序部署、任务自动化等多个场景。本文将介绍Ansible的基本架构、主要功能以及最佳实践,帮助企业更高效地进行IT运维管理。......
  • ANSIBLE
    ANSIBLE云计算核心职能搭建平台架构日常运营保障性能效率优化相关工具代码管理(SCM):GitHub、GitLab、BitBucket、SubVersion构建工具:maven、Ant、Gradle自动部署:Capistrano、CodeDeploy持续集成(CI):Jenkins、Travis配置管理:Ansible、SaltStack、Chef、Puppet容器:Docke......
  • 自动化部署ansible
    ANSIBLE自动化部署安装ANSIBLE########yum源安装###############[[email protected]]#vimCentOS-Base.repo#加入epel源[epel]name=gnbaseurl=https://mirrors.aliyun.com/epel/$releasever/x86_64https://mirrors.cloud.tencent.com/epel/$releasever/x86_6......
  • Ansible fact变量与魔法变量
    目录fact变量1.1fact变量的引用ansible的魔法变量1.魔法变量的使用1.1魔法变量的实际使用fact变量在常用模块里就提到过setup模块,这个模块会收集被控端的信息,而这个模块收集信息的方式就是依赖于fact,返回的是json格式的数据[ansible@masteransible]$ansibleall-msetup......
  • Ansible的变量
    目录Ansible的变量1.在主机清单中定义1.1定义内置变量1.2定义内置变量使用提权1.3给主机组定义变量1.4定义自定义变量2.通过vars定义变量3.通过vars_files定义变量4.通过host_vars和group_vars定义变量5.注册变量Ansible的变量ansible支持变量,用于存储会在整个项目中重......
  • Ansible playbook
    目录Playbook(剧本)1.yaml1.1yaml的语法规则1.2yaml的数据类型1.3yaml的示例2.ansible-playbook2.1playbook入门2.2执行playbook2.3使用playbook安装软件3.更多示例Playbook(剧本)我们之前执行ansble是通过ad-hoc的方式来执行的,这样执行的好处就是我的任务只有1个的时......
  • Ansible的常用模块
    目录ansible常用模块1.file模块1.1file模块的选项1.2file模块的使用1.2.1使用file模块在远程主机创建文件1.2.2创建目录1.2.3删除文件/目录2.copy模块2.1copy模块的选项2.2copy模块的使用3.yum_repository模块3.1yum_repository的选项3.2yum_repository的使用4.yum......
  • Ansible笔记
    1、Ansible基本介绍Ansible是一个自动化的管理IT资源的工具。1)Ansible基本介绍Ansible功能Ansbile优点Ansible缺点系统环境配置无客户的效率低、易挂起安装仁济推送式持续集成丰富的module热回滚基于YAML的Playbook2)Ansible与其他软件的对比......
  • 10、ansible-YAML-非标记语言-剧本的编写-.yaml -剧本执行ansible-playbook-handlers
     ============================================================剧本的编写==================================================通过YAML编写一个剧本,完成web的部署,配置,启动的全过程1、先将目标主机的网站服务卸载ansibleall-myum-a'name=httpdstate=removed'-o·a......
  • 9、ansible-Ad-Hoc-点对点模式--m shell-shell模块(执行的就是linux命令)
    作用:可以执行任何有效的shell命令,包括管道、重定向和其他shell特性。该模块将在远程主机上启动一个shell,然后在该shell中执行命令。执行结果可以作为任务的输出返回,也可以将其保存到文件或变量中供后续任务使用。请注意,与其他模块相比,shell模块的执行效率较低,因为它需要在......