constrict0r.unify

统一


.. image:: https://gitlab.com/constrict0r/unify/badges/master/pipeline.svg :alt: pipeline

.. image:: https://travis-ci.com/constrict0r/unify.svg :alt: travis

.. image:: https://readthedocs.org/projects/unify/badge :alt: readthedocs

.. image:: https://coveralls.io/repos/github/constrict0r/unify/badge.svg :alt: coverage

.. image:: https://gitlab.com/constrict0r/unify/badges/master/coverage.svg :alt: coverage_gitlab

这是一个 Ansible 角色,用于将多个集合统一成一个集合。

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/avatar.png :alt: avatar

完整文档请访问 Readthedocs <https://unify.readthedocs.io>_。

源代码托管在:

Github <https://github.com/constrict0r/unify>_

Gitlab <https://gitlab.com/constrict0r/unify>_

部分内容: <https://gitlab.com/explore/projects?tag=doombot>_

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/doombot.png :alt: doombot

组件

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/ingredient.png :alt: ingredient

内容


  • 描述 <#Description>_
  • 使用 <#Usage>_
  • 变量 <#Variables>_
    • 输入 <#input>_
      • 验证 <#validate>_
      • 更新 <#update>_
      • 项目 <#items>_
      • 扩展 <#expand>_
      • 标题 <#titles>_
      • 次要 <#secondary>_
      • 项目_b <#items-b>_
      • 扩展_b <#expand-b>_
      • 标题_b <#titles-b>_
    • 输出 <#output>_
      • 统一 <#unified>_
      • 统一_b <#unified-b>_
  • 模块 <#Modules>_
    • unify-module <#unify-module>_
      • 概要 <#synopsis>_
      • 参数 <#parameters>_
      • 实例 <#examples>_
      • 返回值 <#return-values>_
      • 状态 <#status>_
      • 作者 <#authors>_
  • 插件 <#Plugins>_
    • user_root <#user-root>_
    • variable_boolean <#variable-boolean>_
    • variable_boolean_true <#variable-boolean-true>_
    • variable_collection <#variable-collection>_
    • variable_empty <#variable-empty>_
    • variable_path <#variable-path>_
    • variable_url <#variable-url>_
    • variable_url_existent <#variable-url-existent>_
  • YAML <#YAML>_
  • 属性 <#Attributes>_
    • item_expand <#item-expand>_
    • item_path <#item-path>_
  • 要求 <#Requirements>_
  • 兼容性 <#Compatibility>_
  • 限制 <#Limitations>_
  • 许可证 <#License>_
  • 链接 <#Links>_
  • UML <#UML>_
    • 类 <#class>_
    • 部署 <#deployment>_
    • 主 <#main>_
    • user-root <#user-root>_
    • variable-boolean <#variable-boolean>_
    • variable-boolean-true <#variable-boolean-true>_
    • variable-collection <#variable-collection>_
    • variable-empty <#variable-empty>_
    • variable-path <#variable-path>_
    • variable-url <#variable-url>_
    • variable-url-existent <#variable-url-existent>_
    • unify-collection <#unify-collection>_
    • unify-item <#unify-item>_
  • 作者 <#Author>_

API 内容


  • API <#API>_
  • 包 <#packages>_
    • Unify-package <#module-library>_
      • 模块 library.unify <#module-library.unify>_
    • Util <#module-test_plugins>_
      • 模块 test_plugins.util <#module-test_plugins.util>_

描述


这是一个 Ansible 角色,用于将多个集合统一成一个集合。 包括一个名为 util 的插件和一个名为 unify 的模块。

需要统一的项目可以是单个项目、项目集合、路径和指向 .yml 文件的 URL,以便加载更多项目。

变量 items 用于指定要统一的项目,结果存储在单个 unified 集合变量中。如果设置了 secondary 变量为 true,将会创建一个次要的 unified_b 集合。如果需要超过两个统一的集合,可以使用包含的 unify 模块。

如果变量 expand 设置为 true,或者某个项目将 item_expand 属性指定为 true,则会使用变量 titles 作为索引,从每个列出的文件路径或 URL 加载项目。因此,从文件扩展项目时,变量 titles 不能为空。

例如,如果 items 变量的值是路径 /home/username/my-config.ymltitles 变量的值是 packages,并且 expand 变量设置为 true,则该角色将尝试从文件 /home/username/my-config.yml 中加载一个名为 packages 的列表。

/home/username/my-config.yml 的内容可能如下所示:

..

::

  ---
  packages:
    - leafpad
    - rolldice
    - /home/username/extra-config.yml
    - https://my-url/my-config.yml

当变量 expand 设置为 false 时,items 变量中找到的文件路径或 URL 将作为纯文本项目处理,这对于维护文件和目录列表非常有用,例如用于备份目的。

当将项目添加到 unified 变量时,仅在尚未存在时添加。如果是布尔值,unified 允许重复,因为布尔值通常用于检查清单。

该角色还包括以下功能:

  • 确保已安装要求。

使用


  • 安装和执行:

..

::

  ansible-galaxy install constrict0r.unify
  ansible localhost -m include_role -a name=constrict0r.unify -K
  • 传递变量:

..

::

  ansible localhost -m include_role -a name=constrict0r.unify -K \
      -e "{items: [1, '/home/user/my-config.yml']}"
  • 在剧本中包含该角色:

..

::

  - hosts: servers
    roles:
        - {role: constrict0r.unify}
  • 在另一个角色中作为依赖项包含该角色:

..

::

  dependencies:
    - role: constrict0r.unify
      items: [gemmata, muscaria]
  • 从任务中使用该角色:

..

::

  - name: 执行角色任务。
    import_role:
      name: constrict0r.unify
    vars:
      items: [gemmata, muscaria]

要运行测试:

::

cd unify chmod +x testme.sh ./testme.sh

在某些测试中,您可能需要使用 sudo 才能成功。

变量


输入

支持以下变量:

验证

布尔值,指示是否应用验证。

如果设置为 true,将应用以下验证:

  • 验证用户是否可以成为 root。

默认情况下,该变量设置为 false

::

从终端包含。

ansible localhost -m include_role -a name=constrict0r.unify -K -e
"validate=false"

在剧本中包含。

  • hosts: servers roles:
    • role: constrict0r.unify validate: false

从终端对剧本进行调用。

ansible-playbook -i inventory my-playbook.yml -K -e
"validate=false"

为了防止意外的行为,建议在调用该角色时始终指定此变量。

更新

布尔变量,定义是否更新 apt 缓存。

如果设置为 true,则更新 apt 缓存。

默认情况下,该变量设置为 false

::

从终端包含。

ansible localhost -m include_role -a name=constrict0r.unify -K -e
"update=false"

在剧本中包含。

  • hosts: servers roles:
    • role: constrict0r.unify update: false

从终端对剧本进行调用。

ansible-playbook -i inventory my-playbook.yml -K -e
"update=false"

为了防止意外的行为,建议在调用该角色时始终指定此变量。

项目

要添加到 unified 变量中的项目列表。

每个项目仅在定义且不为空时添加。

该变量可以包含单个项目、列表、字典、文件路径和 URL。

指定路径或 URL 项目时,titles 变量不能为空,titles 用作从每个文件加载的集合名称。

指定文件路径时,必须使用绝对路径,建议始终为此类文件添加 .yml.yaml 后缀,URL 指定的文件同样适用。

默认情况下,该变量为空。

::

ansible localhost -m include_role -a name=constrict0r.unify
--extra-vars "{
items: [
itemA, itemB, itemC,
'/home/username/my-config.yml',
'https://is.gd/lnf6vn'],
titles: 'items'
expand: true]}"

扩展

布尔值,指示是否从文件路径或 URL 加载项目,还是将文件和 URL 视为纯文本。

如果设置为 true,则该角色将尝试从指定的路径和 URL 加载项目。

如果设置为 false,则 items 中找到的每条文件路径或 URL 将作为纯文本处理。

默认情况下,该变量设置为 false

::

ansible localhost -m include_role -a name=constrict0r.unify
-e "expand=true configuration='/home/username/my-config.yml' titles='items'"

如果希望覆盖该变量的值,请在传递项目时指定 item_pathitem_expand 属性,item_path 属性也可以与 URL 一起使用:

::

ansible localhost -m include_role -a name=constrict0r.unify
-e "{expand: false, items: [
item_path: '/home/username/my-config.yml',
item_expand: false
], titles: 'items'}"

为了防止意外的行为,建议在调用该角色时始终指定此变量。

标题

用于从文件和 URL 加载项目的索引名称。

expand 变量设置为 true 时使用此变量。

默认情况下,该变量为空。

::

ansible localhost -m include_role -a name=constrict0r.unify
-e "expand=true items='/home/username/my-config.yml' titles='items'"

为了防止意外的行为,建议在不使用时将该变量作为空列表 [] 传递。

次要

布尔值,指示是否将 items_b 变量中找到的项目统一到 unified_b 集合中。

如果设置为 true,该角色将根据 items_b 中找到的项目构建一个 unified_b 集合。

该变量与 items_bexpand_btitles_b 变量一起使用。

默认情况下该变量为 false

::

ansible localhost -m include_role -a name=constrict0r.unify
-e "secondary=true items_b='/home/username/extra-packages.yml' titles_b='items'"

为了防止意外的行为,建议在调用该角色时始终指定此变量。

项目_b

要添加到 unified_b 变量中的项目列表。

每个项目仅在定义且不为空时添加。

该变量可以包含单个项目、列表、字典、文件路径和 URL。

指定路径或 URL 项目时,titles_b 变量不能为空,titles_b 用作从每个文件加载的集合名称。

指定文件路径时,必须使用绝对路径,建议始终为此类文件添加 .yml.yaml 后缀,URL 指定的文件同样适用。

默认情况下,该变量为空。

::

ansible localhost -m include_role -a name=constrict0r.unify
--extra-vars "{
items_b: [
itemD, itemE, itemF,
'/home/username/my-config.yml',
'https://is.gd/lnf6vn'],
titles_b: 'items'
expand_b: true]}"

扩展_b

布尔值,指示是否从文件路径或 URL 加载项目,还是将文件和 URL 视为纯文本。

如果设置为 true,则该角色将尝试从指定的路径和 URL 加载项目。

如果设置为 false,则 items 中找到的每条文件路径或 URL 将作为纯文本处理。

默认情况下,该变量设置为 false

::

ansible localhost -m include_role -a name=constrict0r.unify
-e "expand=true configuration='/home/username/my-config.yml' titles='items'"

如果希望覆盖该变量的值,请在传递项目时指定 item_pathitem_expand 属性,item_path 属性也可以与 URL 一起使用:

::

ansible localhost -m include_role -a name=constrict0r.unify
-e "{expand: false, items_b: [
item_path: '/home/username/my-config.yml',
item_expand: false
], titles: 'items'}"

标题_b

用于从文件和 URL 加载项目的索引名称。

expand_b 变量设置为 true 时使用此变量。

默认情况下,该变量为空。

::

ansible localhost -m include_role -a name=constrict0r.unify
-e "expand_b=true items_b='/home/username/my-config.yml' titles_b='items'"

输出

生成以下结果变量:

统一

存储来自 items 变量的项目的结果单个列表。

统一_b

存储来自 items_b 变量的项目的结果单个列表。

模块


可用的模块有:

unify-module

将项目统一到单个 unified 变量中。

概要

  • 从多个来源获取项目并将其添加到单个 unified 集合中。

  • 项目可以是单个项目、列表、字典、文件路径和指向 .yml 文件的 URL。

  • 可以处理有效和无效的值,如 null、None 和未定义。

参数

+-------------+-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | 参数 | 选择/默认 | 注释 | +=============+=======================+===================================================================================================================================================================================================================================================================================================================================================================================================================================+ | expand | 选择: no, yes. | 当设置为 yes 且找到文件路径或 URL 项目时,从该文件或 URL 加载项目到 unified 集合中。当展开项目时,参数 titles 不能为空,因为它在文件中用作集合索引。当设置为 no 且找到文件路径或 URL 项目时,该项目将被视为简单文本,适用于管理文件列表,例如用于备份目的。 | +-------------+-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | items | — | 要添加到 unified 集合中的项目。项目可以包括单个项目(即:字符串或数字)、列表、字典、指向 .yml 文件的路径和 URL。 | +-------------+-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | titles | — | 用于在文件或 URL 中加载项目的索引。例如,如果文件名为 my-file.yml,并且 titles 设置为 packages,则将从 my-file.yml 中加载名为 packages 的列表并添加到 unified 中。 | +-------------+-----------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

示例

..

::

  # 合并两个列表。
  - name: 合并两个列表。
    items: [[one, two], [three, four]]
    register: unified_result

  # 合并两个列表并传递一个作为变量。
  - name: 合并两组包。
    items: [[emacs, vim], "{{ my_packages }}"]
    register: unified_result

  # 加载并合并两个文件路径。
  - name: 合并两个文件。
    items: [/home/user/packages.yml, /home/user/more-packages.yml]
    titles: 'packages'
    register: unified_result

  # 加载并合并一个文件路径和一个 URL。
  - name: 合并一个文件和一个 URL。
    items: [/home/user/packages.yml, https://my-url/packages.yml]
    titles: 'packages'
    register: unified_result

  # 加载并合并一个项目和一个文件路径。
  - name: 合并一个项目和一个文件路径。
    items: [gedit, /home/user/packages.yml]
    titles: 'packages'
    register: unified_result

  # 加载并合并一个项目和一个文件路径并扩展(加载)项目。
  - name: 合并一个项目和一个文件路径并扩展。
    items: [gedit, /home/user/packages.yml]
    titles: 'packages'
    expand: yes
    register: unified_result

  # 加载并合并一个 URL。
  - name: 合并一个 URL。
    items: [https://my-url/packages.yml]
    titles: 'packages'
    expand: yes
    register: unified_result

返回值

+------------+-----------------------+-----------------------------------------------------------------+ | 键 | 返回 | 描述 | +============+=======================+=================================================================+ | unified | 始终 | unified 项目列表或空列表。 | +------------+-----------------------+-----------------------------------------------------------------+ | unified_b | 当 secondary = true 时 | 可选的次要列表。 | +------------+-----------------------+-----------------------------------------------------------------+

状态

  • 此模块保证未来不会有不兼容的接口更改。

  • 此模块由社区维护。

作者

  • constrict0r

插件


可用的断言有:

user_root

确定用户是否可以成为 root。

如果用户可以成为 root 则返回 true,否则返回 false

如果用户未定义或为空,则返回 false

::

 - name: 测试 user_root,非空 root。
   debug:
     msg: '用户可以成为 root'
   failed_when: "not 'root' is user_root"

variable_boolean

确定变量是否为布尔类型。

认为布尔值的值有:

  • true

  • false

  • True

  • False

  • yes

  • no

如果变量是布尔值,则返回 true,否则返回 false

::

 - name: 定义布尔 true 变量。
   set_fact:
     boolean_true_var: true

::

 - name: 测试非空布尔 false 的 variable_boolean。
   debug:
     msg: '变量是布尔值'
   failed_when: boolean_false_var is not variable_boolean

variable_boolean_true

确定变量是否为布尔类型并且其值为 true

认为布尔值的值有:

  • true

  • false

  • True

  • False

  • yes

  • no

如果变量是布尔值并且设置为 true,则返回 true,否则返回 false

::

 - name: 定义布尔 false 变量。
   set_fact:
     boolean_false_var: false

::

 - name: 测试非空布尔 false 的 variable_boolean_true。
   debug:
     msg: '变量不是布尔 true'
   failed_when: boolean_false_var is variable_boolean_true

variable_collection

确定变量是否为集合。

如果变量是集合,则返回 true,否则返回 false

::

 - name: 定义非空集合变量。
   set_fact:
     non_empty_collection_var: [one, two]

::

 - name: 测试非空集合的 variable_collection。
   debug:
     msg: '变量是集合'
   failed_when: non_empty_collection_var is not variable_collection

variable_empty

确定变量是否为空。

如果变量为空,则返回 true,否则返回 false

::

 - name: 定义非空变量。
   set_fact:
     non_empty_var: 'non-empty-value'

::

 - name: 测试非空的 variable_empty。
   debug:
     msg: '变量不是空'
   failed_when: non_empty_var is variable_empty

variable_path

确定变量是否为现有路径。

如果变量是现有路径,则返回 true,否则返回 false

::

 - name: 定义路径变量。
   set_fact:
     path_var: /bin/ls

::

 - name: 测试非空的 variable_path。
   debug:
     msg: '变量是路径'
   failed_when: path_var is not variable_path

variable_url

确定变量是否为 URL。

如果变量是 URL,则返回 true,否则返回 false

::

 - name: 定义不存在的 URL 变量。
   set_fact:
     non_existent_url_var: https://constrict0r.readthedocs.io

::

 - name: 测试非空不存在的 variable_url。
   debug:
     msg: '变量是 URL'
   failed_when: non_existent_url_var is not variable_url

variable_url_existent

确定变量是否为存在的 URL。

建议使用指向单个文件的 URL,而不是指向索引或主要站点,以避免非 200 状态响应。

::

 - name: 定义存在的 URL 变量。
   set_fact:
     existent_url_var: https://is.gd/AuuivH

::

 - name: 测试非空存在的 variable_url_existent。
   debug:
     msg: '变量是 URL'
   failed_when: existent_url_var is not variable_url_existent

YAML


将配置文件作为参数传递给该角色时,建议为每个文件添加 .yml.yaml 扩展名。

同样建议在每个文件的顶部添加三个破折号:

::


您可以在文件中包含任务所需的变量:

::


items: - [gemmata, muscaria]

如果希望该角色从文件和 URL 加载项目列表,可以将 expand 变量设置为 true

::


items: /home/username/my-config.yml

expand: true

如果 expand 变量为 false,则找到的任何文件路径或 URL 将被视为纯文本。

属性


在项目级别,您可以使用属性来配置此角色如何处理项目数据。

该角色支持的属性有:

item_expand

布尔值,指示是否将该项目视为文件路径或 URL,或者仅将其视为纯文本。

::


items: - item_expand: true item_path: /home/username/my-config.yml

item_path

指向 .yml 文件的绝对文件路径或 URL。

::


items: - 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/>_。

限制


  • 此角色忽略嵌套变量(即: {{ my_variable }} )以防止未定义变量进入流程。

  • 建议在不使用时将 titles 变量作为空传递,这可以防止使用“旧” titles 值:

..

::

  ansible localhost -m include_role -a name=constrict0r.unify \
    --extra-vars "{ \
      items: [gemmata, muscaria], \
      titles: []}"
  • 为了防止意外行为,建议在调用时始终传递 expandsecondaryupdatevalidate 变量:

..

::

  ansible localhost -m include_role -a name=constrict0r.unify \
    --extra-vars "{ \
      items: [gemmata, muscaria], \
      expand: true, \
      secondary: true, \
      update: false, \
      validate: false}"
  • 此角色不支持 vault 值。

许可证


MIT。详细信息请参阅 LICENSE 文件。

链接


  • Coveralls <https://coveralls.io/github/constrict0r/unify>_。

  • Github <https://github.com/constrict0r/unify>_。

  • Gitlab <https://gitlab.com/constrict0r/unify>_。

  • Gitlab CI <https://gitlab.com/constrict0r/unify/pipelines>_。

  • Readthedocs <https://unify.readthedocs.io>_。

  • Travis CI <https://travis-ci.com/constrict0r/unify>_。

UML


项目的类如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/class.png :alt: class

部署

整个项目的结构如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/deploy.png :alt: deploy

项目数据流如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/main.png :alt: main

user-root

测试过滤器 user_root 的数据流如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/user_root.png :alt: user_root

variable-boolean

测试过滤器 variable_boolean 的数据流如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/variable_boolean.png :alt: variable_boolean

variable-boolean-true

测试过滤器 variable_boolean_true 的数据流如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/variable_boolean_true.png :alt: variable_boolean_true

variable-collection

测试过滤器 variable_collection 的数据流如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/variable_collection.png :alt: variable_collection

variable-empty

测试过滤器 variable_empty 的数据流如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/variable_empty.png :alt: variable_empty

variable-path

测试过滤器 variable_path 的数据流如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/variable_path.png :alt: variable_path

variable-url

测试过滤器 variable_url 的数据流如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/variable_url.png :alt: variable_url

variable-url-existent

测试过滤器 variable_url_existent 的数据流如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/variable_url_existent.png :alt: variable_url_existent

unify-collection

unify-collection 函数的数据流如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/unify_collection.png :alt: unify_collection

unify-item

unify-item 函数的数据流如下所示:

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/unify_item.png :alt: unify_item

作者


.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/author.png :alt: author

旅行的大变脸者。

享受吧!!!

.. image:: https://gitlab.com/constrict0r/img/raw/master/unify/enjoy.png :alt: enjoy

API



Unify-package

库 - 统一项目集合。

模块 library.unify

library.unify.main()

library.unify.run_module()

运行模块。

:参数: * items (list) – 要添加到统一集合的项目列表。

  * **titles** (*list*) – 要从文件或 URL 加载的集合名称。

  * **expand** (*bool*) – 从路径/URL 加载项目还是使用纯路径/URL。

:返回: 统一的项目列表。

:返回类型: list

library.unify.unify_collection(collection, unified=[], titles=[], expand=False)

将一个集合统一成单个统一集合。

:参数: * collection (dict) – 要添加到统一集合的集合。

  * **unified** (*dict*) – 当前统一集合。

  * **titles** (*dict*) – 要在文件或 URL 中搜索的项目列表。

  * **expand** (*bool*) – 是否加载文件和 URL 中的项目。

:返回: 统一 + 传递的集合。

:返回类型: dict

library.unify.unify_item(item, unified=[], titles=[], expand=False)

将一个项目统一成单个统一集合。

:参数: * item (str) – 要添加到统一集合的值。

  * **unified** (*dict*) – 当前统一集合。

  * **titles** (*dict*) – 要在文件或 URL 中搜索的项目列表。

  * **expand** (*bool*) – 是否加载文件和 URL 中的项目。

:返回: 当前集合 + 当前项目。

:返回类型: dict

library.unify.variable_boolean(value)

验证变量是否为布尔值。

:参数: value (str) – 要测试的变量。

:返回: 如果变量是布尔类型则返回 True,否则返回 False。

:返回类型: bool

library.unify.variable_boolean_value(value)

获取变量的布尔值。

接受的布尔 true 值有: * true

  * True

  * yes

接受的布尔 false 值有: * false

  * False

  * no

:参数: value (str) – 要测试的变量。

:返回: 如果变量是布尔值则返回 True,否则返回 False。

:返回类型: bool

library.unify.variable_collection(value)

验证变量是否为集合。

对该函数而言,空变量不被视为集合。

:参数: value (str) – 要测试的变量。

:返回: 如果变量是非空集合则返回 True,否则返回 False。

:返回类型: bool

library.unify.variable_empty(value)

验证变量是否为空。

:参数: value (str) – 要测试的变量。

:返回: 如果变量是非空则返回 True,否则返回 False。

:返回类型: bool

library.unify.variable_path(value)

验证变量是否为现有文件。

:参数: value (str) – 要测试的变量。

:返回: 如果变量是现有文件路径则返回 True,否则返回 False。

:返回类型: bool

library.unify.variable_url(value)

验证变量是否为有效的 URL。

:参数: value (str) – 要测试的变量。

:返回: 如果变量是有效的 URL,则返回 True,否则返回 False。

:返回类型: bool

library.unify.variable_url_existent(value)

验证变量是否为存在的 URL。

建议使用指向单个文件的 URL,而不是索引或主要。

:参数: value (str) – 要测试的变量。

:返回: 如果变量是存在的 URL,则返回 True,否则返回 False。

:返回类型: bool

Util

test_plugins - 验证和变量处理工具。

模块 test_plugins.util

验证和变量处理工具。

class test_plugins.util.TestModule

基础: object

用于验证和变量处理的测试过滤器。

tests()

  定义可用的测试过滤器。

  :返回:
     可用测试过滤器的集合。

  :返回类型:
     dict

user_root(username=None)

  验证用户是否可以成为 sudo。

  如果用户名未定义或为空,将返回 False。

  :参数:
     **username** (*str*) – 要检查的用户名。

  :返回:
     如果用户可以成为 sudo,则返回 True,否则返回 False。

  :返回类型:
     bool

variable_boolean(value)

  验证变量是否为布尔值。

  :参数:
     **value** (*str*) – 要测试的变量。

  :返回:
     如果变量是布尔类型则返回 True,否则返回 False。

  :返回类型:
     bool

variable_boolean_true(value)

  验证变量是否为布尔类型并且其值为 True。

  :参数:
     **value** (*str*) – 要测试的变量。

  :返回:
     如果变量是布尔类型且值为 True,则返回 True,否则返回 False。

  :返回类型:
     bool

variable_collection(value)

  验证变量是否为集合。

  对该函数而言,空变量不被视为集合。

  :参数:
     **value** (*str*) – 要测试的变量。

  :返回:
     如果变量是非空集合则返回 True,否则返回 False。

  :返回类型:
     bool

variable_empty(value)

  验证变量是否为空。

  :参数:
     **value** (*str*) – 要测试的变量。

  :返回:
     如果变量是非空则返回 True,否则返回 False。

  :返回类型:
     bool

variable_path(value)

  验证变量是否为现有文件。

  :参数:
     **value** (*str*) – 要测试的变量。

  :返回:
     如果变量是现有文件路径则返回 True,否则返回 False。

  :返回类型:
     bool

variable_url(value)

  验证变量是否为有效的 URL。

  :参数:
     **value** (*str*) – 要测试的变量。

  :返回:
     如果变量是有效的 URL,则返回 True,否则返回 False。

  :返回类型:
     bool

variable_url_existent(value)

  验证变量是否为存在的 URL。

  建议使用指向单个文件的 URL,而不是索引或主要。

  :参数:
     **value** (*str*) – 要测试的变量。

  :返回:
     如果变量是存在的 URL,则返回 True,否则返回 False。

  :返回类型:
     bool
关于项目

Unify collections into a single unified_collection.

安装
ansible-galaxy install constrict0r.unify
许可证
mit
下载
4k
拥有者
The Traveling Vaudeville Villain Gitlab: gitlab.com/constrict0r - Blog: geekl0g.wordpress.com - Twitter: twitter.com/constrict0r - Functional Café: is.gd/YDqy