当前位置:网站首页>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中的信息
单元小结
边栏推荐
- Getting Started with TextBlock Control Basic Tools Usage, Get Started
- DBeaver连接MySQL 8.x时Public Key Retrieval is not allowed 错误解决
- Precautions and solutions when SIGABRT error is reported
- Bilateral filtering acceleration "recommended collection"
- mysql black window ~ build database and build table
- 女性服务社群产品设计
- Grafana安装后web打开报错
- 为什么毕业季不要表白?
- Vb how to connect mysql_vb how to connect to the database collection "advice"
- 微信聊天记录中搜索红包
猜你喜欢
Why don't you make a confession during the graduation season?
Ubantu专题4:xshell、xftp连接接虚拟机以及设置xshell复制粘贴快捷键
Visualize GraphQL schemas with GraphiQL
[CUDA study notes] First acquaintance with CUDA
Ubantu project 4: xshell, XFTP connected the virtual machine and set xshell copy and paste the shortcut
第二届中国PWA开发者日
【MySQL】Mysql范式及外键作用
四象限时间管理有多好用?
Ubuntu Topic 5: Setting a Static IP Address
Browser's built-in color picker
随机推荐
BGP综合实验(建立对等体、路由反射器、联邦、路由宣告及聚合)
多主复制的适用场景(1)-多IDC
[MySQL] Mysql paradigm and the role of foreign keys
Codeforces Round #796 (Div. 2) (A-D)
what exactly is json (c# json)
Ubantu专题4:xshell、xftp连接接虚拟机以及设置xshell复制粘贴快捷键
三、数组
Female service community product design
DBeaver连接MySQL 8.x时Public Key Retrieval is not allowed 错误解决
R language ggplot2 visualization: use the ggboxplot function of the ggpubr package to visualize the box plot, use the font function to customize the font size, color, style (bold, italic) of the legen
What is the difference between BI software in the domestic market?
435. 无重叠区间
The normal form of the database (first normal form, second normal form, third normal form, BCNF normal form) "recommended collection"
工程力学复习资料
工程流体力学复习
mysql black window ~ build database and build table
update data table update
json到底是什么(c# json)
01 Encounter typescript, build environment
Kubernetes原理剖析与实战应用手册,太全了