sap.sap_operations.valid_hostname test – Return true if string provided is valid sap hostname as per SAP note 611361

Note

This test plugin is part of the sap.sap_operations collection.

It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install sap.sap_operations.

To use it in a playbook, specify: sap.sap_operations.valid_hostname.

New in sap.sap_operations 2.14.0

Synopsis

  • Return true if string provided is valid sap hostname as per SAP note 611361

  • Description in the SAP note 611361 is a bit ambiguous, so here are the rules that define valid hostname.

  • Valid hostname should only contain alphanumeric characters and ‘-’

  • Valid hostname should be lowercase (by default, see all_lowercase parameter and examples)

  • Valid hostname does not start with a number

  • Valid hostname does not end with a ‘-’

  • Valid hostname is no longer than 13 characters (see parameter le and examples below)

  • Valid hostname is at least on character long (see parameter ge)

Keyword parameters

This describes keyword parameters of the test. These are the values key1=value1, key2=value2 and so on in the following examples: input is sap.sap_operations.valid_hostname(key1=value1, key2=value2, ...) and input is not sap.sap_operations.valid_hostname(key1=value1, key2=value2, ...)

Parameter

Comments

all_lowercase

boolean

Check if hostname is all lowercase

Choices:

  • false

  • true ← (default)

ge

integer

Minimum length of the hostname (ge = greater of equal)

Default: 1

le

integer

Maximum length of the hostname (le = less or equal)

Default: 13

value

string / required

Value to check

Notes

Note

  • This module is community supported

  • Module interface (parameters, output) expected to be stable but not guaranteed

  • Module planned to be released on Ansible Automation Hub after collecting some feedback

  • There is no guarantee that this module will be officially supported by Red Hat

Examples

---
- name: Hostname with alphanumeric characters is valid
  ansible.builtin.assert:
    that: ('hostname13' is sap.sap_operations.valid_hostname)

- name: Very long hostname is not valid
  ansible.builtin.assert:
    that: ('this-is-longer-than13' is not sap.sap_operations.valid_hostname)

- name: Very long hostname is not valid unless you say so
  ansible.builtin.assert:
    that: ('this-is-longer-than13' is sap.sap_operations.valid_hostname(le=140))

- name: Hostname with capital letters is not considered valid by default
  ansible.builtin.assert:
    that: ('Hostname' is not sap.sap_operations.valid_hostname)

- name: Hostname with capital letters can also be valid
  ansible.builtin.assert:
    that: ('Hostname' is sap.sap_operations.valid_hostname(all_lowercase=False))

- name: Hostname cannot start with a number
  ansible.builtin.assert:
    that: ('1hostname' is not sap.sap_operations.valid_hostname)

- name: Hostname cannot end with '-'
  ansible.builtin.assert:
    that: ('hostname-' is not sap.sap_operations.valid_hostname)

- name: Hostname should contain only alphanumeric characters and '-'
  ansible.builtin.assert:
    that: ('host?name' is not sap.sap_operations.valid_hostname)

- name: Hostname should contain only alphanumeric characters and '-'
  ansible.builtin.assert:
    that: ('host.name' is not sap.sap_operations.valid_hostname)

- name: Empty string is not valid hostname
  ansible.builtin.assert:
    that: ('' is not sap.sap_operations.valid_hostname)

Return Value

Key

Description

Return value

boolean

True if value provided is valid sap hostname

Returned: success

Authors

  • Kirill Satarin (@kksat)

Hint

Configuration entries for each entry type have a low to high priority order. For example, a variable that is lower in the list will override a variable that is higher up.