jonaspammer.core_dependencies

// 该文件由 .github/workflows/gh-pages.yml 生成 - 所有本地更改最终会丢失! = ansible-role-core_dependencies Jonas Pammer opensource@jonaspammer.at; :toc: left :toclevels: 2 :toc-placement!: :source-highlighter: rouge

https://galaxy.ansible.com/jonaspammer/core_dependencies[image:https://img.shields.io/badge/available%20on%20ansible%20galaxy-jonaspammer.core_dependencies-brightgreen[在 Galaxy 上的版本]] // 非常相关的状态徽章 https://github.com/JonasPammer/ansible-role-core_dependencies/actions/workflows/ci.yml[image:https://github.com/JonasPammer/ansible-role-core_dependencies/actions/workflows/ci.yml/badge.svg[测试 CI]]

这是一个 Ansible 角色,用于安装执行各种 Ansible 核心模块所需的系统包,具体包括:

  • ansible.builtin.apt_repository
  • ansible.builtin.archive
  • ansible.builtin.debconf
  • ansible.builtin.dnf
  • ansible.builtin.git
  • ansible.builtin.subversion
  • ansible.builtin.unarchive
  • ansible.builtin.user
  • ansible.builtin.yum
  • ansible.posix.seboolean

此角色还确保大多数系统的软件包缓存是最新的。

在大多数情况下,您会希望将此角色与我的 https://github.com/JonasPammer/ansible-role-bootstrap[`bootstrap` 角色]结合使用。

[注意] .免责声明 ===== 此角色是 https://github.com/robertdebock/ansible-role-core_dependencies/releases/tag/2.1.9[robertdebock/ansible-role-core_dependencies v2.1.9 on GitHub (2022年2月11日)] 的一个分支 (https://github.com/robertdebock/ansible-role-core_dependencies/compare/2.1.9...master[比较此处的更改]) (Apache 许可证 2.0,版权归 Robert de Bock (robert@meinit.nl) 所有),目前只是添加了代码注释。 =====

toc::[]

[[meta]] == 🔎 元数据 以下是...

.link:meta/main.yml[] [source,yaml]



galaxy_info: role_name: "core_dependencies" description: "一个用于安装依赖项以支持 Ansible 核心模块的 ansible 角色。 基于 robertdebock 的 core_dependencies 角色。"

author: "jonaspammer" license: "MIT"

min_ansible_version: "2.11" platforms: - name: EL # (企业Linux) versions: - "9" # 当前测试:rockylinux9 - name: Fedora versions: - "38" # 当前测试:fedora38 - "39" # 当前测试:fedora39 - name: Debian versions: - bullseye # 当前测试:debian11 - bookworm # 当前测试:debian12 - name: Ubuntu versions: - focal # 当前测试:ubuntu2004 - jammy # 当前测试:ubuntu2204

galaxy_tags: []

dependencies: []

[[requirements]] == 📌 需求 // 在此说明任何此角色或 Ansible 自身中可能未涵盖的前提条件。 Ansible 用户需要能够 become

必须在 Ansible 控制器上安装 https://galaxy.ansible.com/community/general[`community.general` 集合]。

[[variables]] == 📜 角色变量 // 此角色的可设置变量的描述应在这里 // 以及通过角色参数可以/应该设置的任何变量。 // 从其他角色和/或全局作用域(即 hostvars、group vars 等)读取的任何变量 // 也应在此提及。

[[public_vars]] == 📜 此角色定义的事实/变量

本节中列出的每个变量 在执行此角色时动态定义(仅能通过 ansible.builtin.set_facts 重写)并且 旨在不仅用于内部。

[[tags]] == 🏷️ 标签

// 请查看 https://github.com/tribe29/ansible-collection-tribe29.checkmk/blob/main/roles/server/README.md#tags // 了解如何使用标签分组任务的精彩示例

任务标记如下 https://docs.ansible.com/ansible/latest/user_guide/playbooks_tags.html#adding-tags-to-roles[标签]:

[cols="1,1"] |=== |标签 | 目的

2+| 此角色尚未正式记录标签。

// | download-xyz // | // | install-prerequisites // | // | install // | // | create-xyz // | |===

您可以使用 Ansible 跳过任务,或仅运行某些任务。默认情况下,当未指定标签时会运行所有任务。

[[dependencies]] == 👫 依赖关系 // 此处应列出其他角色, // 以及可能需要为其他角色设置的参数的任何详细信息, // 或从其他角色使用的变量。

[[example_playbooks]] == 📚 示例剧本用法 // 包含如何在剧本中使用此角色的常见场景示例总是对用户有利。

[注意]

此角色是我 https://github.com/JonasPammer/ansible-roles[ 多个兼容目的角色]的一部分。

机器需要准备好。 在 CI 中,这在 molecule/resources/prepare.yml 中完成 它从 requirements.yml 获取其软依赖项:

.link:molecule/resources/prepare.yml[] [source,yaml]



  • name: prepare hosts: all become: true gather_facts: false

    roles:

    • role: jonaspammer.bootstrap

以下图表是此角色的“软依赖项”的汇总 以及它们的软依赖项的递归树。

image:https://raw.githubusercontent.com/JonasPammer/ansible-roles/master/graphs/dependencies_core_dependencies.svg[ jonaspammer.core_dependencies 的 requirements.yml 依赖图] ====

.最小可行剧本

[source,yaml]


  • hosts: servers:&provisioned name: 启动由 Ansible 管理的 Linux 机器。 gather_facts: false

    roles:

    • role: jonaspammer.core_dependencies

====

.更常见的剧本

[source,yaml]


  • hosts: servers:&provisioned name: 启动由 Ansible 管理的 Linux 机器。 become: false gather_facts: false

    roles:

    • role: jonaspammer.bootstrap
    • role: jonaspammer.core_dependencies become: "{{ bootstrap_become | default(omit) }}" become_user: "{{ bootstrap_become_user | default(omit) }}"

====

[[tested-distributions]] == 🧪 测试过的发行版

一个角色可以在不同的 发行版 上工作,比如 Red Hat 企业 Linux (RHEL), 即使没有针对该确切发行版的测试。 // 参考什么来遵循 -- geerlingguy 最多欢迎星标和固定的项目: // https://github.com/geerlingguy/ansible-role-docker/blob/master/.github/workflows/ci.yml |=== | 操作系统系列 | 发行版 | 发行版发布日期 | 发行版生命周期结束日期 | 附带的 Docker 镜像

// https://endoflife.date/rocky-linux | Rocky | Rocky Linux 8 (https://www.howtogeek.com/devops/is-rocky-linux-the-new-centos/[伪装的 RHEL/CentOS 8]) | 2021-06 | 2029-05 | https://github.com/geerlingguy/docker-rockylinux8-ansible/actions?query=workflow%3ABuild[image:https://github.com/geerlingguy/docker-rockylinux8-ansible/workflows/Build/badge.svg?branch=master[CI]]

| Rocky | Rocky Linux 9 | 2022-07 | 2032-05 | https://github.com/geerlingguy/docker-rockylinux9-ansible/actions?query=workflow%3ABuild[image:https://github.com/geerlingguy/docker-rockylinux9-ansible/workflows/Build/badge.svg?branch=master[CI]]

// https://endoflife.date/fedora (13个月) | RedHat | Fedora 39 | 2023-11 | 2024-12 | https://github.com/geerlingguy/docker-fedora39-ansible/actions?query=workflow%3ABuild[image:https://github.com/geerlingguy/docker-fedora39-ansible/workflows/Build/badge.svg?branch=master[CI]]

// https://ubuntu.com/about/release-cycle | Debian | Ubuntu 20.04 LTS | 2021-04 | 2025-04 | https://github.com/geerlingguy/docker-ubuntu2004-ansible/actions?query=workflow%3ABuild[image:https://github.com/geerlingguy/docker-ubuntu2004-ansible/workflows/Build/badge.svg?branch=master[CI]]

| Debian | Ubuntu 22.04 LTS | 2022-04 | 2027-04 | https://github.com/geerlingguy/docker-ubuntu2204-ansible/actions?query=workflow%3ABuild[image:https://github.com/geerlingguy/docker-ubuntu2204-ansible/workflows/Build/badge.svg?branch=master[CI]]

// https://wiki.debian.org/DebianReleases // https://wiki.debian.org/LTS | Debian | Debian 11 | 2021-08 | 2024-06 (2026-06 LTS) | https://github.com/geerlingguy/docker-debian11-ansible/actions?query=workflow%3ABuild[image:https://github.com/geerlingguy/docker-debian11-ansible/workflows/Build/badge.svg?branch=master[CI]]

| Debian | Debian 12 | 2023-06 | 2026-06 (2028-06 LTS) | https://github.com/geerlingguy/docker-debian12-ansible/actions?query=workflow%3ABuild[image:https://github.com/geerlingguy/docker-debian12-ansible/workflows/Build/badge.svg?branch=master[CI]] |===

[[tested-ansible-versions]] == 🧪 测试过的 Ansible 版本

测试的 ansible 版本尽量与 https://github.com/ansible-collections/community.general#tested-with-ansible[ Ansible 的 community.general 集合的支持模式]保持一致。 截至写作时为:

  • 2.13 (Ansible 6)
  • 2.14 (Ansible 7)
  • 2.15 (Ansible 8)
  • 2.16 (Ansible 9)

[[development]] == 📝 开发 // 关于此项目的约定的徽章 https://conventionalcommits.org[image:https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg[常规提交]] https://results.pre-commit.ci/latest/github/JonasPammer/ansible-role-core_dependencies/master[image:https://results.pre-commit.ci/badge/github/JonasPammer/ansible-role-core_dependencies/master.svg[pre-commit.ci 状态]] // image:https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white[pre-commit, link=https://github.com/pre-commit/pre-commit]

[[development-system-dependencies]] === 📌 开发机器依赖

  • Python 3.10 或更高版本
  • Docker

[[development-dependencies]] === 📌 开发依赖 开发依赖在名为 requirements-dev.txthttps://pip.pypa.io/en/stable/user_guide/#requirements-files[pip 需求文件]中定义。 以下是 Linux 的示例安装说明:


“可选”:创建一个python虚拟环境并为当前 shell 会话激活它

$ python3 -m venv venv $ source venv/bin/activate

$ python3 -m pip install -r requirements-dev.txt

[[development-guidelines]] === ℹ️ Ansible 角色开发指南

请查看我的 https://github.com/JonasPammer/cookiecutter-ansible-role/blob/master/ROLE_DEVELOPMENT_GUIDELINES.adoc[ Ansible 角色开发指南]。

如果有兴趣,我还写下了一些 https://github.com/JonasPammer/cookiecutter-ansible-role/blob/master/ROLE_DEVELOPMENT_TIPS.adoc[ 一般 Ansible 角色开发(最佳)实践]。

[[versioning]] === 🔢 版本控制

版本使用 https://git-scm.com/book/en/v2/Git-Basics-Tagging[标签] 定义, 这些标签反过来被 https://galaxy.ansible.com/docs/contributing/version.html[Ansible Galaxy 识别和使用]。

版本不能以 v 开头。

当新标签被推送时, https://github.com/JonasPammer/ansible-role-core_dependencies/actions/workflows/release-to-galaxy.yml[ 一个 GitHub CI 工作流] (image:https://github.com/JonasPammer/ansible-role-core_dependencies/actions/workflows/release-to-galaxy.yml/badge.svg[发布 CI]) 负责将角色导入到我的 Ansible Galaxy 账户。

[[testing]] === 🧪 测试 使用 GitHub Workflows 在每次贡献时运行自动测试。

测试主要围绕在 <<tested-distributions,不同的 Linux 发行版>> 上运行 https://molecule.readthedocs.io/en/latest/[Molecule】 和使用 <<tested-ansible-versions,各种 ansible 版本>>。

分子测试还包括一个步骤,该步骤使用 https://github.com/ansible/ansible-lint#readme[`ansible-lint`] 遍历所有 ansible 剧本,以检查最佳实践和可能改进的行为。

要运行测试,只需在命令行上运行 tox。 您可以传递一个可选的环境变量来定义将由 molecule 启动的 Docker 容器的发行版:


$ MOLECULE_DISTRO=ubuntu2204 tox

有关传递给 MOLECULE_DISTRO 的可能值列表,请查看在 link:.github/workflows/ci.yml[] 中定义的矩阵。

==== 🐛 调试 Molecule 容器

  1. 使用选项 MOLECULE_DESTROY=never 运行您的分子测试,例如:
  • [subs="quotes,macros"]

$ MOLECULE_DESTROY=never MOLECULE_DISTRO=#ubuntu1604# tox -e py3-ansible-#5# ... 任务 [ansible-role-pip : (省略)] pass:[************************] 失败: [instance-py3-ansible-9] => changed=false ... pass:[___________________________________ 概述 ____________________________________] pre-commit: 命令成功 错误: py3-ansible-9: 命令失败


  1. 找到分子提供的 Docker 容器的名称:
  • [subs="quotes"]

$ docker ps #30e9b8d59cdf# geerlingguy/docker-debian12-ansible:latest "/lib/systemd/systemd" 8 minutes ago Up 8分钟 instance-py3-ansible-9


  1. 进入容器的 bash Shell,进行调试:
  • [subs="quotes"]

$ docker exec -it #30e9b8d59cdf# /bin/bash

root@instance-py3-ansible-2:/#

  • [提示]

    如果您尝试调试的失败属于您的 verify.yml 步骤,而非实际的 converge.yml, 您可能想知道 Ansible 的模块 (vars)、主机 (hostvars) 和 环境变量的输出已存储在提供者和 Docker 机器上的文件中:
  • /var/tmp/vars.yml(在 hostvars 键下包含主机变量)
  • /var/tmp/environment.yml

    grepcat 或按需传输这些文件!

  • [提示]

    您还可能想知道上面通知中的文件 附加在给定工作流运行的 GitHub CI 工件 中。+ 这使人们能够检查运行之间的差异 从而帮助调试造成比特腐蚀或一般故障的原因。

image::https://user-images.githubusercontent.com/32995541/178442403-e15264ca-433a-4bc7-95db-cfadb573db3c.png[]

  1. 调试完成后,退出并销毁容器:
  • [subs="quotes"]

root@instance-py3-ansible-2:/# exit

$ docker stop #30e9b8d59cdf#

$ docker container rm #30e9b8d59cdf# $ docker container prune


==== 🐛 本地调试已安装的包版本

尽管这是 tox 3 的标准功能,但目前 https://github.com/tox-dev/tox/pull/2794[只有在 tox 识别到 CI 变量时]才会发生。 例如:


$ CI=true tox

[[development-container-extra]] === 🧃 提示:容器化理想开发环境

本项目提供“1-Click 容器化开发环境”的定义。

该容器甚至允许您在其内部运行 Docker 容器(Docker-In-Docker,dind), 允许执行分子操作。

要使用它:

  1. 确保您满足 link:https://code.visualstudio.com/docs/remote/containers#_system-requirements[ Visual Studio Code 开发容器的系统要求], 可选择地遵循链接页面部分的 安装 - 部分。+ 这包括:安装 Docker、安装 Visual Studio Code 本身,以及安装必要的扩展。
  2. 克隆该项目到您的机器
  3. 在 Visual Studio Code 中打开存储库目录(_文件 - 打开文件夹..._)。
  4. 如果您在右下角的提示中看到 devcontainer 定义的存在, 您可以按相应的按钮进入它。 否则,您也可以自己执行 Visual Studio 命令 Remote-Containers: Open Folder in Container视图 - 命令面板 -> _输入提到的命令_)。

[提示]

我建议您在的确有时发生的问题时使用 Remote-Containers: Rebuild Without Cache and Reopen in Container, 因为 devcontainer 功能有时会有些问题,无法正确识别其定义中所做的更改。 ====

[注意]

您可能需要配置主机系统以使容器能够使用您的 SSH/GPG 密钥。

该过程在 https://code.visualstudio.com/remote/advancedcontainers/sharing-git-credentials[ 官方 devcontainer 文档中的“与容器共享 Git 凭据”部分]中进行了描述。 =====

[[cookiecutter]] === 🍪 CookieCutter

本项目应与 https://github.com/JonasPammer/cookiecutter-ansible-role[最初开模板的 CookieCutter]保持同步 使用 https://github.com/cruft/cruft[cruft](如果可能)或手动更改(如有必要)尽可能保持一致。

. cruft update 的官方示例用法


image::https://raw.githubusercontent.com/cruft/cruft/master/art/example_update.gif[`cruft update` 的官方示例用法]


==== 🕗 更新日志 推送新标签时,存储库维护者将创建相应的 GitHub 发布,以提供有标题和描述的适当更改日志。

[[pre-commit]] === ℹ️ 一般代码检查和样式约定 一般的代码检查和样式约定通过各种 https://pre-commit.com/[`pre-commit`] 钩子至少在某种程度上 自动 要求符合标准。

在每次贡献时,使用 https://pre-commit.ci/[`pre-commit.ci`] 进行自动执行<<note_pre-commit-ci,*>>。 拉取请求甚至会自动由同一工具修复, 至少是由自动改变文件的钩子。

[注意]

不要混淆: 尽管某些预提交钩子可能能够警告您关于脚本分析的语法缺陷或代码缺陷(出于这个原因,预提交的钩子是 测试套件的一部分), 但预提交本身并不会运行任何真正的测试套件。 有关测试的信息,请参见 <>。 ====

[提示]

[[note_pre-commit-ci]] 不过,我建议您将预提交集成到您自己本地的开发工作流程中。

这可以通过进入您克隆项目的目录并运行 pre-commit install 来完成。 这样做会使 git 在您每次提交时运行预提交检查, 如果钩子发出警报则会终止提交。

您还可以通过随时运行 pre-commit run --all-files 来执行预提交的钩子。例如。

[[contributing]] == 💪 贡献 https://open.vscode.dev/JonasPammer/ansible-role-core_dependencies[image:https://img.shields.io/static/v1?logo=visualstudiocode&label=&message=Open%20in%20Visual%20Studio%20Code&labelColor=2c2c32&color=007acc&logoColor=007acc[在 Visual Studio Code 中打开]] image:https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square[欢迎提交 PR]

// 包含在 README.adoc 中 :toc: :toclevels: 3

以下各节内容具有通用性质,旨在帮助新贡献者。 本项目的实际“开发文档”在 <> 下找到。

=== 🤝 开头 首先,感谢您考虑为本项目做出贡献。

遵循这些指南有助于传达您尊重管理和开发此开源项目的开发者的时间。 作为回报,他们应通过处理您的问题、评估更改和帮助您完成拉取请求来回馈这种尊重。

[[cookiecutter--contributing]] === 🍪 CookieCutter 本项目的许多文件均源于 https://github.com/JonasPammer/cookiecutter-ansible-role[最初开模板的 CookieCutter]。

请检查您所考虑的修改是否确实适用于该模板, 如果适用,则在模板中进行适当的更改。 您的更改也可以部分适用于该模板 以及部分适用于此项目的某些特定内容, 在这种情况下,您将创建多个 PR。

=== 💬 常规提交

普通贡献者无需担心遵循 https://github.com/JonasPammer/JonasPammer/blob/master/demystifying/conventional_commits.adoc[__规范__] https://www.conventionalcommits.org/en/v1.0.0/[__按定义__], 因为拉取请求会被压缩合并为项目中的一个提交。 只有核心贡献者,即有权推送到此项目分支的人员,必须遵循此规则 (例如,以便自动版本确定和变更日志生成生效)。

=== 🚀 开始入门

贡献通过问题和拉取请求(PRs)进行到此存储库。 以下是覆盖这两者的一些一般指南:

==== 问题

问题应用于报告问题、请求新功能或在创建 PR 之前讨论潜在更改。 当您 https://github.com/JonasPammer/ansible-role-core_dependencies/issues/new[ 创建新问题]时,将加载一个模板,引导您收集和提供我们需要进行调查的信息。

如果您发现一个解决您遇到的问题的问题, 请将您自己的重现信息添加到现有问题中 而不是创建一个新问题。 添加 https://github.blog/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/[反应] 也可以帮助向我们的维护者表明某个特定问题影响的不仅仅是报告者。

==== 拉取请求

对本项目的 PR 始终欢迎,这也是快速使您的修复或改进列入下一个版本的好方法。 https://blog.ploeh.dk/2015/01/15/10-tips-for-better-pull-requests/[通常而言],PR 应:

  • 仅修复/添加相关功能 解决普遍存在的空白/样式问题,而不是两者兼具。
  • 为修复或更改的功能(如果已存在测试套件)添加单元或集成测试。
  • 关注一个特定问题
  • 包括文档在存储库中
  • 附带完整的拉取请求模板(在创建PR时自动加载)。

对于涉及核心功能或可能需要进行重大更改的更改(例如重大版本发布), 最好先打开一个问题以讨论您的提案。

通常,我们遵循“分叉和拉取”的 Git 工作流程

  1. 将存储库分叉到您的 GitHub 帐户
  2. 将项目克隆到您的机器
  3. 在本地创建一个简洁但描述性的分支
  4. 将更改提交到该分支
  5. 遵循与此存储库特定的任何格式和测试指南
  6. 将更改推送到您的分叉
  7. 在我们的存储库中打开 PR,并遵循 PR 模板,以便我们能够有效审查更改。

[[changelog]] == 🗒 更新日志 有关相应的更新日志,请参见 https://github.com/JonasPammer/ansible-role-core_dependencies/releases[此存储库的发布页面] 其中包含相应的 https://github.com/JonasPammer/ansible-role-core_dependencies/tags[标签(版本)]。

注意本项目遵循语义版本控制。 请报告任何小版本更新的意外重大更改。

[[license]] == ⚖️ 许可证 .link:LICENSE[]


MIT 许可证

版权 (c) 2022, Jonas Pammer

特此免费授予任何获得本软件及相关文档文件(统称“软件”)副本的人 处理软件,没有任何限制,包括但不限于使用、复制、修改、合并、出版、分发、再授权和/或出售 软件副本的权利,并允许向其提供软件的人这样做,须遵守以下条件:

上述版权声明和本许可声明应包含在所有副本或重要部分的软件中。

软件是按“原样”提供的,不附带任何形式的保证,无论明示或暗示,包括但不限于适销性、适合特定目的和不侵权的保证。在任何情况下,版权拥有者或版权持有人都不对因使用或其他交易软件而产生的任何索赔、损害或其他责任负责,无论是在合同、侵权或其他情况下。


关于项目

An ansible role for installing dependecies to support the Ansible core modules. Based on robertdebock's core_dependencies role.

安装
ansible-galaxy install jonaspammer.core_dependencies
许可证
mit
下载
71.6k
拥有者
DevOps is just FullStack with one additional layer