constrict0r.sourcez
源代码
.. image:: https://gitlab.com/constrict0r/sourcez/badges/master/pipeline.svg :alt: 管道
.. image:: https://travis-ci.com/constrict0r/sourcez.svg :alt: travis
.. image:: https://readthedocs.org/projects/sourcez/badge :alt: readthedocs
Ansible 角色,用于将仓库添加到 apt 源。
.. image:: https://gitlab.com/constrict0r/img/raw/master/sourcez/avatar.png :alt: 头像
完整文档见 Readthedocs <https://sourcez.readthedocs.io>
_。
源代码托管在:
Github <https://github.com/constrict0r/sourcez>
_。
Gitlab <https://gitlab.com/constrict0r/sourcez>
_。
部分: <https://gitlab.com/explore/projects?tag=doombot>
_
.. image:: https://gitlab.com/constrict0r/img/raw/master/sourcez/doombot.png :alt: doombot
成分
.. image:: https://gitlab.com/constrict0r/img/raw/master/sourcez/ingredient.png :alt: 成分
内容
描述 <#Description>
_用法 <#Usage>
_变量 <#Variables>
_repositories <#repositories>
_configuration <#configuration>
_
YAML <#YAML>
_属性 <#Attributes>
_item_expand <#item-expand>
_item_path <#item-path>
_
要求 <#Requirements>
_兼容性 <#Compatibility>
_许可证 <#License>
_链接 <#Links>
_UML <#UML>
_部署 <#deployment>
_主要 <#main>
_
作者 <#Author>
_
描述
Ansible 角色,用于将 apt 仓库添加到 apt 源。
该角色执行以下操作:
确保安装所需的依赖。
确保当前用户具有管理员(root)权限。
如果定义了 repositories 变量,则将其列出的仓库添加到 apt 源。
如果定义了 configuration 变量,则将其列出的仓库添加到 apt 源。
用法
- 安装和执行:
..
::
ansible-galaxy install constrict0r.sourcez
ansible localhost -m include_role -a name=constrict0r.sourcez -K
- 传递变量:
..
::
ansible localhost -m include_role -a name=constrict0r.sourcez -K \
-e "{repositories: [{name: multimedia, repo: 'deb http://www.debian-multimedia.org sid main'}]}"
- 在剧本中包含该角色:
..
::
- hosts: servers
roles:
- {role: constrict0r.sourcez}
- 将角色作为另一个角色的依赖项:
..
::
dependencies:
- role: constrict0r.sourcez
repositories: [{name: multimedia, repo: 'deb http://www.debian-multimedia.org sid main'}]
- 从任务中使用该角色:
..
::
- name: 执行角色任务。
import_role:
name: constrict0r.sourcez
vars:
repositories: [{name: multimedia, repo: 'deb http://www.debian-multimedia.org sid main'}]
运行测试:
::
cd sourcez chmod +x testme.sh ./testme.sh
某些测试可能需要使用 sudo 才能成功。
变量
支持以下变量:
repositories
要添加到 apt 源的仓库列表。
通过在剧本中包含角色时传递 repositories 数组,或通过终端的 –extra-vars 选项,可以修改此列表。
默认情况下,此变量为空。
::
从终端包含。
ansible localhost -m include_role -a name=constrict0r.sourcez -K -e
"{repositories: [{
name: multimedia,
repo: 'deb http://www.debian-multimedia.org sid main'
}]}}"
在剧本中包含。
- hosts: servers
roles:
- role: constrict0r.sourcez
repositories:
- name: multimedia repo: deb http://www.debian-multimedia.org sid main
- role: constrict0r.sourcez
repositories:
从终端传递给剧本。
ansible-playbook -i inventory my-playbook.yml -K -e
"{repositories: [{
name: multimedia,
repo: 'deb http://www.debian-multimedia.org sid main'
}]}}"
configuration
指向包含本角色所支持的所有或部分变量的 .yml 文件的绝对文件路径或 URL。
建议为 configuration 文件使用 .yml 或 .yaml 扩展名。
默认情况下,此变量为空。
::
使用文件路径。
ansible localhost -m include_role -a name=constrict0r.sourcez -K -e
"configuration=/home/username/my-config.yml"
使用 URL。
ansible localhost -m include_role -a name=constrict0r.sourcez -K -e
"configuration=https://my-url/my-config.yml"
要了解如何编写配置文件,请参阅 YAML 文件格式部分。
YAML
当将配置文件作为参数传递给此角色时,建议为每个文件添加 .yml 或 .yaml 扩展名。
还建议在每个文件的顶部添加三个破折号:
::
您可以在文件中包含任务所需的变量:
::
repositories: - [{name: multimedia, repo: 'deb http://www.debian-multimedia.org sid main'}]
如果您希望该角色从文件和 URL 中加载项目列表,可以将 expand 变量设置为 true:
::
repositories: /home/username/my-config.yml
expand: true
如果 expand 变量为 false,则任何找到的文件路径或 URL 将被视为纯文本。
属性
在项目级别,您可以使用属性来配置此角色处理项目数据的方式。
此角色支持的属性有:
item_expand
一个布尔值,指示是否将此项目视为文件路径或 URL,还是仅将其视为纯文本。
::
repositories: - item_expand: true item_path: /home/username/my-config.yml
item_path
指向 .yml 文件的绝对文件路径或 URL。
::
repositories: - item_path: /home/username/my-config.yml
此属性也适用于 URL。
要求
Ansible <https://www.ansible.com>
_ >= 2.8。Jinja2 <https://palletsprojects.com/p/jinja/>
_。Pip <https://pypi.org/project/pip/>
_。Python <https://www.python.org/>
_。PyYAML <https://pyyaml.org/>
_。Requests <https://2.python-requests.org/en/master/>
_。
如果您想运行测试,您还需要:
Docker <https://www.docker.com/>
_。Molecule <https://molecule.readthedocs.io/>
_。Setuptools <https://pypi.org/project/setuptools/>
_。
兼容性
Debian Buster <https://wiki.debian.org/DebianBuster>
_。Debian Raspbian <https://raspbian.org/>
_。Debian Stretch <https://wiki.debian.org/DebianStretch>
_。Ubuntu Xenial <http://releases.ubuntu.com/16.04/>
_。
许可证
MIT。详细信息见 LICENSE 文件。
链接
Github <https://github.com/constrict0r/sourcez>
_。Gitlab <https://gitlab.com/constrict0r/sourcez>
_。Gitlab CI <https://gitlab.com/constrict0r/sourcez/pipelines>
_。Readthedocs <https://sourcez.readthedocs.io>
_。Travis CI <https://travis-ci.com/constrict0r/sourcez>
_。
UML
部署
下面显示了完整的项目结构:
.. image:: https://gitlab.com/constrict0r/img/raw/master/sourcez/deploy.png :alt: 部署
主要
项目数据流如下所示:
.. image:: https://gitlab.com/constrict0r/img/raw/master/sourcez/main.png :alt: 主要
作者
.. image:: https://gitlab.com/constrict0r/img/raw/master/sourcez/author.png :alt: 作者
旅行的歌舞小丑。
祝好运!!!
.. image:: https://gitlab.com/constrict0r/img/raw/master/sourcez/enjoy.png :alt: 享受
Add apt repositories to Debian sources.
ansible-galaxy install constrict0r.sourcez