# Ansible

### 开发自定义模块

{% embed url="<https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html>" %}

### 任务运行时间统计

配置ansible.cfg

```
[defaults]
callback_whitelist = profile_tasks
```

### 错误日志格式化

配置ansible.cfg

```
[defaults]
stdout_callback = yaml
```

可选值：

### 加速器

安装mitogen加速模块

```
pip install mitogen
```

配置ansible.cfg

```
[defaults]
strategy = mitogen_linear
strategy_plugins = /usr/lib/python2.7/site-packages/ansible_mitogen/plugins/strategy
```

### Q\&A

**Q: 如何获取ansible主控机器地址**

```
- debug: var="{{ ansible_env['SSH_CLIENT'].split() | first }}"
```

**Q: playbook运行卡在gather\_facts**

将gather\_facts信息采集改为最少

```
[default]
gather_subset = min
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://viva.gitbook.io/project/kai-fa/ansible.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
