跳至内容

Ansible 开发环境

类似 pip 的 Ansible 集合安装方式。

沟通

  • 加入 Ansible 论坛

  • 获取帮助:获得帮助或帮助他人。请在发起新讨论时添加合适的标签。

  • 社交空间:与其他爱好者一起交流互动。
  • 新闻和公告:追踪项目范围内的公告,包括社交活动。
  • Bullhorn 新闻通讯:用于发布版本和重要更改。

有关沟通的更多信息,请参阅Ansible 沟通指南

功能

  • 提倡“临时”开发方法
  • 确保当前开发环境隔离
  • 安装所有集合的 Python 依赖项
  • 安装所有集合的测试依赖项
  • 检查缺少的系统软件包
  • 将当前集合符号链接到当前 Python 解释器的 site-packages
  • 将所有集合的依赖项安装到当前 Python 解释器的 site-packages
  • 在可用时使用uv env代替 Python 的 venv 来提高性能。可以使用SKIP_UV=1禁用。

通过将集合放置到 Python 的 site-packages 目录中,Ansible、Python 和 pytest 都可以发现它们。

使用方法

设置开发环境

推荐

安装ansible-dev-environment的**推荐**方法是使用ansible-dev-tools包。Ansible 开发工具旨在简化创建Ansible内容所需的多个工具的设置和使用。它将关键的 Ansible 开发包组合到一个统一的 Python 包中。

# This also installs ansible-core if it is not already installed
pip3 install ansible-dev-tools
pip3 install ansible-dev-environment --user
$ git clone <collection_repo>
$ cd <collection_repo>
$ ade install -e .\[test] --venv .venv
INFO: Found collection name: network.interfaces from /home/bthornto/github/network.interfaces/galaxy.yml.
INFO: Creating virtual environment: /home/bthornto/github/network.interfaces/venv
INFO: Virtual environment: /home/bthornto/github/network.interfaces/venv
INFO: Using specified interpreter: /home/bthornto/github/network.interfaces/venv/bin/python
INFO: Requirements file /home/bthornto/github/network.interfaces/requirements.txt is empty, skipping
INFO: Installing python requirements from /home/bthornto/github/network.interfaces/test-requirements.txt
INFO: Installing ansible-core.
INFO: Initializing build directory: /home/bthornto/github/network.interfaces/build
INFO: Copying collection to build directory using git ls-files.
INFO: Running ansible-galaxy to build collection.
INFO: Running ansible-galaxy to install collection and it's dependencies.
INFO: Removing installed /home/bthornto/github/network.interfaces/venv/lib64/python3.11/site-packages/ansible_collections/network/interfaces
INFO: Symlinking /home/bthornto/github/network.interfaces/venv/lib64/python3.11/site-packages/ansible_collections/network/interfaces to /home/bthornto/github/network.interfaces
WARNING: A virtual environment was specified but has not been activated.
WARNING: Please activate the virtual environment:
source venv/bin/activate

拆除开发环境

$ ade uninstall ansible.scm
INFO     Found collection name: ansible.scm from /home/bthornto/github/ansible.scm/galaxy.yml.
INFO     Requirements file /home/bthornto/github/ansible.scm/requirements.txt is empty, skipping
INFO     Uninstalling python requirements from /home/bthornto/github/ansible.scm/test-requirements.txt
INFO     Removed ansible.utils: /home/bthornto/github/ansible.scm/venv/lib64/python3.11/site-packages/ansible_collections/ansible/utils
INFO     Removed ansible.utils*.info: /home/bthornto/github/ansible.scm/venv/lib64/python3.11/site-packages/ansible_collections/ansible.utils-2.10.3.info
INFO     Removed ansible.scm: /home/bthornto/github/ansible.scm/venv/lib64/python3.11/site-packages/ansible_collections/ansible/scm
INFO     Removed collection namespace root: /home/bthornto/github/ansible.scm/venv/lib64/python3.11/site-packages/ansible_collections/ansible
INFO     Removed collection root: /home/bthornto/github/ansible.scm/venv/lib64/python3.11/site-packages/ansible_collections

帮助

ade --help

ade install --help

ade uninstall --help