当前位置:网站首页>ansible study notes 02
ansible study notes 02
2022-07-31 15:32:00 【51CTO】
ansible的inventory文件
文件定义了ansible管理的主机,或主机组
静态inventory文件
用txtfile of text records,包括主机的ip地址,域名等信息,只要不修改inventory文件内容,The managed hosts will not change
动态inventory文件
Get dynamic information from the database,The information changes as the database changes,In most casesjson格式输出
inventory文件
一个简单的inventory文件
定义主机组
通过方括号[]括起来,A host file can belong to multiple groups
Groups can be nested within groups
Define the host range
使用[start:end]定义范围
注意事项
如果主机和主机组重名了,ansible会忽略主机组,选择主机名,配置inventoryDocumentation tries to avoid this from happening.
查看主机信息
命令: ansible 主机名or组名 -i 路径 --list-hosts
参数 | 含义 |
---|---|
-i | 指定inventory文件路径,默认路径是/etc/ansible/hosts,Do not specify this parameter,It will enter the default path search |
–list-hosts | List host information |
all | List all host group information |
ungrouped | List non-host group information |
ansible的配置文件
ansibleConfiguration files are not global,Any user can have their ownansible配置文件
配置文件的优先级
路径 | 优先级 |
---|---|
/etc/ansible/ansible.cfg | 最低 |
~/.ansible.cfg(家目录下) | 低 |
./ansible.cfg(当前目录下) | 中(建议使用) |
ANSIBLE_CONFIG(global variable assignment) | 高 |
ANSIBLE_CONFIG不建议使用,一旦使用,All users will point to this path
使用默认的ansible.cfg
Use the home directory.ansible.cfg
Use the current directoryansible.cfg
ansible配置文件的相关参数
ansibleConfiguration file exercise
创建目录/home/student/deploy-manage
目录下有ansible.cfg文件,Inventory文件也在该目录下
InventoryThe host group for the file is as follows
[myself] 拥有主机localhost
[intranetweb] 拥有主机 servera.lab.example.com
[internetweb] 拥有主机 serverb.lab.example.com
[web] Nested groups own host groups intranetweb 和 internetweb
在ansible.cfg增加[privilege_escalation]选项,能够使用sudo方式提权,提权到root用户,并且输入密码
ansible ad hoc 命令
ad hoc:临时的,one line throughansiblecommand to execute at the beginning,使用起来非常的简单,快速.
使用格式: ansible host-pattern -m moudle [-a ‘moudle arguments’] [-i inventory]
模块分类 | 模块 |
---|---|
文件模块 | copy、file、lineinfile、synchronize |
软件包模块 | package、yum、apt、dnf、gem、pip |
系统模块 | firewalld、service、user、reboot |
Net工具 | get_url(下载)、nmcli(设置网卡)、uri(与web交互) |
ad hoc方式,使用ping模块
ad hoc方式,使用user模块添加用户
ad hoc方式,使用userThe module removes the user
ad hoc方式,使用copy模块
ad hoc方式,使用command模块1
ad hoc缺省值就是command,It can be omitted when used -m command参数
配置文件参数 | command选项 |
---|---|
inventory | -i |
remote_user | -u |
become | –become,-b |
become_method | –become-method |
become_user | –become-user |
become_ask_pass | –ask-become-pass,-K |
ad hoc方式,使用command模块2
ad hoc相关练习
1、 查看ansible版本
2、 新建文件夹/home/student/deploy-review
3、 在文件夹内创建ansible.cfg,指定inventory目录为:/home/student/deploy-review/inventory,Specifies the login user asdevops
4 、创建子目录/home/student/deploy-review/inventory,inventory文件从:从http://materials.example.com/labs/deploy-review/inventory下载
5、 使用ansible ad hoc 中commandThe module looks at the hostid信息
6、 使用ansible ad hoc 中copyModule will text:This server is managed by Ansible. \n 输出到/etc/motd中
7、 Run the question again6相同的ad hoc,查看现象
8、 使用ansible ad hoc 中command模块查看/etc/motd中的信息
单元小结
边栏推荐
猜你喜欢
随机推荐
使用 GraphiQL 可视化 GraphQL 架构
Efficient use of RecyclerView Section 2
json到底是什么(c# json)
Grafana安装后web打开报错
长得很怪的箱图
SIGABRT 报错时的注意事项和解决方法
实现防抖与节流函数
The use of border controls
mysql黑窗口~建库建表
双边滤波加速「建议收藏」
BGP综合实验(建立对等体、路由反射器、联邦、路由宣告及聚合)
ML.NET相关资源整理
腾讯云部署----DevOps
AVH部署实践 (一) | 在Arm虚拟硬件上部署飞桨模型
Unity中实现点选RenderTexture中的3D模型
C language "the third is" upgrade (mode selection + AI chess)
The R language ggstatsplot package ggbarstats function visualizes bar charts, and adds hypothesis test results (including sample number, statistics, effect size and its confidence interval, significan
Word table to Excel
浏览器自带的拾色器
Snake Project (Simple)