sap.sap_operations.valid_hostname filter – Return true if string provided is valid sap hostname as per SAP note 611361
Note
This filter 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 filter. These are the values key1=value1
, key2=value2
and so on in the following
example: input | sap.sap_operations.valid_hostname(key1=value1, key2=value2, ...)
Parameter |
Comments |
---|---|
Check if hostname is all lowercase Choices:
|
|
Minimum length of the hostname (ge = greater of equal) Default: |
|
Maximum length of the hostname (le = less or equal) Default: |
|
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' | sap.sap_operations.valid_hostname)
- name: Very long hostname is not valid
ansible.builtin.assert:
that: not ('this-is-longer-than13' | sap.sap_operations.valid_hostname)
- name: Very long hostname is not valid unless you say so
ansible.builtin.assert:
that: ('this-is-longer-than13' | sap.sap_operations.valid_hostname(le=140))
- name: Hostname with capital letters is not considered valid by default
ansible.builtin.assert:
that: not ('Hostname' | sap.sap_operations.valid_hostname)
- name: Hostname with capital letters can also be valid
ansible.builtin.assert:
that: ('Hostname' | sap.sap_operations.valid_hostname(all_lowercase=False))
- name: Hostname cannot start with a number
ansible.builtin.assert:
that: not ('1hostname' | sap.sap_operations.valid_hostname)
- name: Hostname cannot end with '-'
ansible.builtin.assert:
that: not ('hostname-' | sap.sap_operations.valid_hostname)
- name: Hostname should contain only alphanumeric characters and '-'
ansible.builtin.assert:
that: not ('host?name' | sap.sap_operations.valid_hostname)
- name: Hostname should contain only alphanumeric characters and '-'
ansible.builtin.assert:
that: not ('host.name' | sap.sap_operations.valid_hostname)
- name: Empty string is not valid hostname
ansible.builtin.assert:
that: not ('' | sap.sap_operations.valid_hostname)
Return Value
Key |
Description |
---|---|
True if value provided is valid sap hostname Returned: success |