validations_libs.community.init_validation module¶
- class validations_libs.community.init_validation.CommunityValidation(validation_name, validation_dir='/usr/share/ansible/validation-playbooks', ansible_base_dir='/usr/share/ansible')[source]¶
Bases:
object
Init Community Validation Role and Playbook Command Class
Initialize a new community role using ansible-galaxy and create a playboook from a template.
- create_playbook(content="---\n# This playbook has been generated by the `validation init` CLI.\n#\n# As shown here in this template, the validation playbook requires three\n# top-level directive:\n# ``hosts``, ``vars -> metadata`` and ``roles``.\n#\n# ``hosts``: specifies which nodes to run the validation on. The options can\n# be ``all`` (run on all nodes), or you could use the hosts defined\n# in the inventory.\n# ``vars``: this section serves for storing variables that are going to be\n# available to the Ansible playbook. The validations API uses the\n# ``metadata`` section to read each validation's name and description\n# These values are then reported by the API.\n#\n# The validations can be grouped together by specyfying a ``groups`` metadata.\n# Groups function similar to tags and a validation can thus be part of many\n# groups. To get a full list of the groups available and their description,\n# please run the following command on your Ansible Controller host:\n#\n# $ validation show group\n#\n# The validations can also be categorized by technical domain and acan belong to\n# one or multiple ``categories``. For example, if your validation checks some\n# networking related configuration, you may want to put ``networking`` as a\n# category. Note that this section is open and you are free to categorize your\n# validations as you like.\n#\n# The ``products`` section refers to the product on which you would like to run\n# the validation. It's another way to categorized your community validations.\n# Note that, by default, ``community`` is set in the ``products`` section to\n# help you list your validations by filtering by products:\n#\n# $ validation list --product community\n#\n- hosts: hostname\n gather_facts: false\n vars:\n metadata:\n name: Brief and general description of the validation\n description: |\n The complete description of this validation should be here\n# GROUPS:\n# Run ``validation show group`` to get the list of groups\n# :type group: `list`\n# If you don't want to add groups for your validation, just\n# set an empty list to the groups key\n groups: []\n# CATEGORIES:\n# :type group: `list`\n# If you don't want to categorize your validation, just\n# set an empty list to the categories key\n categories: []\n products:\n - community\n roles:\n - {}\n")[source]¶
Create the playbook for the new community validation
- execute()[source]¶
Execute the actions necessary to create a new community validation
Check if the role name is compliant with Ansible specification Initializing the new role using ansible-galaxy Creating the validation playbook from a template on disk
- Return type:
NoneType
- is_community_validations_enabled(base_config)[source]¶
Checks if the community validations are enabled in the config file
- Parameters:
base_config (
Dict
) – Contents of the configuration file- Return type:
Boolean
- is_playbook_exists()[source]¶
New playbook existence check
This class method checks if the new playbook file is already existing in the official validations catalog and in the current community validations directory.
First, it gets the list of the playbooks yaml file available in
constants.ANSIBLE_VALIDATIONS_DIR
. If there is a match in at least one of the directories, it returnsTrue
, otherwiseFalse
.- Return type:
Boolean
- is_role_exists()[source]¶
New role existence check
This class method checks if the new role name is already existing in the official validations catalog and in the current community validations directory.
First, it gets the list of the role names available in
constants.ANSIBLE_ROLES_DIR
. If there is a match in at least one of the directories, it returnsTrue
, otherwiseFalse
.- Return type:
Boolean
- property is_role_name_compliant¶
Check if the role name is compliant with Ansible Rules
Roles Name are limited to contain only lowercase alphanumeric characters, plus ‘_’ and start with an alpha character.
- Return type:
Boolean
- property playbook_basedir¶
Returns the absolute path of the community playbooks directory
- Return type:
pathlib.PosixPath
- property playbook_name¶
Return the new playbook name with the yaml extension
- Return type:
str
- property playbook_path¶
Returns the absolute path of the new community playbook yaml file
- Return type:
pathlib.PosixPath
- property role_basedir¶
Returns the absolute path of the community validations roles
- Return type:
pathlib.PosixPath
- property role_dir_path¶
Returns the community validation role directory name
- Return type:
pathlib.PosixPath
- property role_name¶
Returns the community validation role name
- Return type:
str