ansible - 如何从 ansible-modules 生成文档
问题描述
我们正在使用像 openstack 这样的 ansible 模块开发一个 ansible 集合:https ://github.com/openstack/ansible-collections-openstack
如何从像 ansible wiki 这样的模块生成文档?https://docs.ansible.com/ansible/2.8/modules/os_auth_module.html#os-auth-module
我在互联网上找到了这个,但我无法让 antsibull 工作
https://www.die-welt.net/2020/07/building-documentation-for-ansible-collections-using-antsibull/
问题是尽管设置了 ANSIBLE_COLLECTIONS_PATH 环境变量,但它只会输出一个几乎为空的文件antsibull-docs collection --use-current --dest-dir ~/docs collectionname
我也不知道这是否是正确的方法。
那么我能做什么呢?
解决方案
您可以使用 antsibull-docs 为自制集合生成文档(rst)。
以下是生成文档的过程。
- 安装
安装ansible。
pip install ansible-base
ansible --version
ansible 2.10.5
- 反牛安装
克隆antsibull repo并安装。
pip install --upgrade pip
git clone https://github.com/ansible-community/antsibull.git
cd antsibull/
pip install poetry
poetry install
cd ..
- 创建收藏目录
这一次,在当前(工作)目录中创建一个集合目录。
根据自制集合更改命名空间。
mkdir -p collections/ansible_collections/{namespace}/
- 将您的集合移动到命名空间目录
mv {your_collection} collections/ansible_collections/{namespace}/
- ansible.cfg 创建
创建 ansible.cfg 以指定集合目录路径。
vi ansible.cfg
[defaults]
COLLECTIONS_PATHS = {your_working_directory_path}/collections
检查配置是否反映。
ansible-config dump --only-changed
COLLECTIONS_PATHS({your_working_directory_path}/ansible.cfg) = ['{your_working_directory_path}/collections']
使用 ansible-doc 检查可以看到的模块文档。
ansible-doc namespace.your_collection.module_name
- 为模块生成 .rst 文件
mkdir -p build/plugin_docs
antsibull-docs collection --use-current --squash-hierarchy --dest-dir ./build/plugin_docs namespace.your_collection
ls ./build/plugin_docs
这样,模块 .rst 文档就在 build/plugin_docs 目录中生成。
如果发生构建错误,请检查 your_collection 目录下的galaxy.yml 中的参数是否错误。
推荐阅读
- python - 在 for 循环中分配新列时将标题名称分配给熊猫数据框的优雅方法?
- android - 在对话框中显示消息的替代方式是什么?
- c# - 根据属性值从 JObject 返回子对象
- java - 使用 Postman 调用 WS 已完成,但不是从 Java 代码
- java - 从本地我可以使用 psql 命令通过终端访问,但无法通过 JAVA 代码连接
- node.js - 使用纬度和经度按地理位置查找到附近
- java - 并发数据结构中非并发数据结构的线程安全
- json - Jstree中错误时间的数据绑定
- objective-c - UIButton 移除样式选中状态
- php - Doctrine MongoDB ODM:如何获取 @Id 的 bin_md5 版本