【CICD】Ansible知识库

一、主机清单配置

1. 配置文件路径

  • 默认路径
    /etc/ansible/hosts
    这是 Ansible 的全局默认库存文件路径,但许多用户可能不会直接使用它。
  • 项目目录或自定义路径
    用户通常会为不同项目创建独立的库存文件,例如:
    当前目录下的 hosts、inventory 或 inventory.ini 文件。
    通过命令行 -i 参数指定路径,例如:
    bash
    ansible-playbook -i /path/to/my_inventory playbook.yml
  • 通过配置覆盖路径
    Ansible 的配置文件 ansible.cfg 可以定义默认库存文件位置。检查以下位置:
    当前目录:./ansible.cfg
    用户家目录:~/.ansible.cfg
    全局配置:/etc/ansible/ansible.cfg
    在 ansible.cfg 中查找 inventory 参数,例如:
ini 复制代码
[defaults]
inventory = /my/custom/inventory_path
  • 通过命令检查当前配置
    运行以下命令查看生效的配置路径:
bash 复制代码
# 这会显示当前生效的库存文件路径。
ansible-config dump | grep DEFAULT_HOST_LIST
  1. 环境变量
    通过 ANSIBLE_INVENTORY 环境变量指定路径:
bash 复制代码
export ANSIBLE_INVENTORY=/path/to/inventory

总结

默认路径:/etc/ansible/hosts

更常见的用法:项目目录下的自定义文件(如 inventory)或通过 -i 参数指定。

优先级:命令行参数 -i > 环境变量 > ansible.cfg > 默认路径。

💡 提示:如果找不到文件,可以通过 ansible-inventory --list 验证当前加载的库存信息

2. 配置语法

相关推荐
User_芊芊君子7 小时前
让异构增量同步飞起来-KFS全链路并行同步方案
运维·自动化·ansible
あ-2 天前
ansible-playbook安装seaweedfs三节点集群
ansible
Tassel_YUE4 天前
非 ansible 主机批量执行命令方法:psssh 和 pscp(随手记)
linux·网络·ssh·scp·ansible
亿朝亿夕13 天前
ansible安装
ansible
.柒宇.14 天前
运维常见面试题_07_配置管理与监控(Ansible · Prometheus · Alertmanager)· 容器编排(Kubernetes)
运维·k8s·ansible·prometheus
相顾若初见14 天前
Ansible部署k8s
容器·kubernetes·ansible
wzq11_66615 天前
ansible部署项目——基于tidb数据库安装zabbix_server
ansible·zabbix·tidb
吃不吃早饭15 天前
RHEL9 搭建 Harbor 私有仓库与 Ansible 自动化部署 Kubernetes 运行环境完整实践
kubernetes·自动化·ansible
wzq11_66615 天前
Ansible自动部署Redis——六步自动安装Redis数据库
ansible
mohesashou16 天前
红帽linux的K8S部署
linux·kubernetes·ansible