当前位置:网站首页>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中的信息
单元小结
边栏推荐
猜你喜欢

.NET 20周年专访 - 张善友:.NET 技术是如何赋能并改变世界的

工程水文学复习资料

TRACE32——基于SNOOPer的变量记录

Synchronized and volatile interview brief summary

【CUDA学习笔记】初识CUDA

Why is the field of hacking almost filled with boys?

微信聊天记录中搜索红包

思路迪医药冲刺港股:5个月亏2.9亿 泰格医药与先声药业是股东

Excel快速对齐表格的中姓名(两个字姓名和三个字姓名对齐)

Getting Started with TextBlock Control Basic Tools Usage, Get Started
随机推荐
MySQL数据库操作
vb中如何连接mysql_vb怎么连接数据库「建议收藏」
为什么黑客领域几乎一片男生?
Gorm—Go language database framework
Word table to Excel
type of timer
Deployment应用生命周期与Pod健康检查
Grafana安装后web打开报错
工程水文学名词解释总结
R语言计算时间序列数据的移动平均值(滚动平均值、例如5日均线、10日均线等):使用zoo包中的rollmean函数计算k个周期移动平均值
Emmet 语法
ML.NET相关资源整理
TRACE32——C源码关联
How useful is four-quadrant time management?
Ubuntu Topic 5: Setting a Static IP Address
删除 状态良好(恢复分区)的磁盘
[MySQL] Mysql paradigm and the role of foreign keys
自动化测试如何创造业务价值?
贪吃蛇项目(简单)
The use of border controls