vagrant ansible 配置

生成 Ansible 配置文件的方法

Ansible 提供了 ansible-config 工具来生成配置文件模板,适用于不同版本的需求。

Ansible 2.12 及更高版本

使用以下命令生成包含所有默认设置(注释状态)的配置文件模板:
ansible-config init --disabled > ansible.cfg

若要包含现有插件的完整配置示例:
ansible-config init --disabled -t all > ansible.cfg

旧版本(如 2.9)

旧版配置文件示例可能不完整,建议参考对应版本的稳定分支代码库。例如 2.9 版本的示例文件:
https://github.com/ansible/ansible/blob/stable-2.9/examples/ansible.cfg

常用基础配置示例

以下是一个禁用 SSH 主机密钥检查的基础配置片段,通常用于测试环境:

ini 复制代码
[defaults]
host_key_checking = False

注意事项

  • 生成的文件中所有选项默认被注释,需根据需求手动取消注释并修改。
  • 生产环境中建议启用 host_key_checking 以确保安全性。
  • 插件相关配置(如 -t all 生成的)需结合实际使用的插件进行调整。

cat /etc/ansible/ansible.cfg

Since Ansible 2.12 (core):

To generate an example config file (a "disabled" one with all default settings, commented out):

$ ansible-config init --disabled > ansible.cfg

Also you can now have a more complete file by including existing plugins:

ansible-config init --disabled -t all > ansible.cfg

For previous versions of Ansible you can check for examples in the 'stable' branches of each version

Note that this file was always incomplete and lagging changes to configuration settings

for example, for 2.9: https://github.com/ansible/ansible/blob/stable-2.9/examples/ansible.cfg

defaults
host_key_checking = False

cat /etc/ansible/hosts

This is the default ansible 'hosts' file.

It should live in /etc/ansible/hosts

- Comments begin with the '#' character

- Blank lines are ignored

- Groups of hosts are delimited by header elements

- You can enter hostnames or ip addresses

- A hostname/ip can be a member of multiple groups

Ex 1: Ungrouped hosts, specify before any group headers:

green.example.com

blue.example.com

192.168.100.1

192.168.100.10

Ex 2: A collection of hosts belonging to the 'webservers' group:

webservers

alpha.example.org

beta.example.org

192.168.1.100

192.168.1.110

If you have multiple hosts following a pattern, you can specify

them like this:

www001:006.example.com

You can also use ranges for multiple hosts:

db-99:101-node.example.com

Ex 3: A collection of database servers in the 'dbservers' group:

dbservers

db01.intranet.mydomain.net

db02.intranet.mydomain.net

10.25.1.56

10.25.1.57

Ex4: Multiple hosts arranged into groups such as 'Debian' and 'openSUSE':

Debian

alpha.example.org

beta.example.org

openSUSE

green.example.com

blue.example.com

**master
192.168.56.100

node

192.168.56.101
192.168.56.102
192.168.56.103

master:vars

ansible_user=vagrant
ansible_password=vagrant
ansible_become=yes
ansible_become_method=sudo
ansible_become_password=vagrant**

node:vars
ansible_user=vagrant
ansible_password=vagrant
ansible_become=yes
ansible_become_method=sudo
ansible_become_password=vagrant

相关推荐
米码收割机1 分钟前
【Python】Django恒达科技门户网站(源码+文档)【独一无二】
数据库·python·科技
沉默de荒年 对月影成5 分钟前
机房断电搞崩服务器 | 人大金仓 V8 全量备份跨实例完整恢复实录
运维·服务器·oracle
艾莉丝努力练剑11 分钟前
【MYSQL】MYSQL学习的一大重点:基本查询(下)
android·数据库·学习·mysql·面试·八股文
冰暮流星20 分钟前
mysql之数据库创建,查询,删除,启用
数据库·mysql·oracle
GIS数据转换器28 分钟前
智慧灌区管理平台
大数据·服务器·网络·数据库·人工智能·生活
寒水馨2 小时前
Linux下载、安装 Codex CLI(附安装包codex-x86_64-unknown-linux-musl.tar.gz)
linux·openai·终端·ai编程·codex·智能体·codex cli
其实防守也摸鱼2 小时前
KMP全栈开发:从Android到AI Agent的技术演进与实践
android·运维·网络·人工智能·学习·安全·macos
777VG9 小时前
PostgreSQL +martin将多张表输出成一个 MVT
前端·数据库·postgresql
aax121345310 小时前
VOC 集群治理工程实操|美丽蓝天绿岛项目 RTO 工艺选型、管控方案与申报要
大数据·数据库·人工智能
IvorySQL10 小时前
PG 日报|优化缓冲区批量扫描,降低多套接字并发竞争
数据库·人工智能·postgresql·开源·区块链