【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. 配置语法

相关推荐
风清再凯2 天前
自动化工具ansible,以及playbook剧本
运维·自动化·ansible
IT乌鸦坐飞机2 天前
ansible部署数据库服务随机启动并创建用户和设置用户有完全权限
数据库·ansible·centos7
遇见火星15 天前
如何使用Ansible一键部署MinIO集群?
ansible
粥周粥15 天前
ANSIBLE
ansible
码农101号15 天前
Linux中ansible模块补充和playbook讲解
linux·运维·ansible
码农101号15 天前
Linux的Ansible软件基础使用讲解和ssh远程连接
ansible
烟雨书信17 天前
ANSIBLE运维自动化管理端部署
运维·自动化·ansible
碎碎-li17 天前
ANSIBLE(运维自动化)
运维·自动化·ansible
@donshu@20 天前
Linux运维-ansible-python开发-获取inventroy信息
linux·运维·ansible
Kendra91923 天前
Ansible
ansible