itnok.is_ubuntu

is-ubuntu

Build Status GitHub tag Ansible Role

This tool checks if the target Ubuntu system is a container or if it is the local machine.

Here’s what it does:

  • Sets a fact called is_ubuntu_localhost
  • Checks if it is running in a container
  • Sets a fact called is_ubuntu_inside_container
  • Checks for any proxy settings

:exclamation: Requirements


No special requirements.

:abcd: Role Variables


Variable Description Default Value
is_force_lookup Forces the lookup for custom facts even if they already exist. no
is_test_url_list A list of URLs to test for Internet access. []

No dependencies.

:loudspeaker: Facts


This role creates the following facts for use in other roles or playbooks:

Fact Description
is_ubuntu_behind_proxy Indicates if the system is behind a proxy.
is_ubuntu_inside_container Returns true if inside a container. This is true if PID 1 is not init or systemd.
is_ubuntu_localhost Returns true if the target machine is localhost.
is_ubuntu_network_reachable Returns true if all URLs in is_test_url_list are reachable (also includes URLs from /etc/apt/sources.list by default).
is_ubuntu_url_reachable_list Lists all reachable URLs.
is_ubuntu_url_unreachable_list Lists all unreachable URLs.

:notebook: Example Playbook


Here is how to use this tool in your playbooks:

---
- hosts: servers
  remote_user: ubuntu   # optional (your remote user)
  gather_facts: yes     # optional

  roles:
    - { role: itnok.is_ubuntu }

:microscope: Testing


This role can be tested using Molecule to ensure it works in a generic environment.

Molecule is not required to use the role but is necessary for testing on local installations or in continuous integration (CI).

You can find an example of using Molecule for CI in this repository's GitHub Actions.

To install Molecule, follow the instructions on the Molecule documentation. If the necessary dependencies are installed, you can run:

$ python3 -m pip install --user "molecule[ansible,docker,lint]"

Tests will run inside containers created specifically for this purpose, so you’ll need Docker installed. If you'd prefer to use Podman, install it with the following command:

$ python3 -m pip install --user "molecule[ansible,podman,lint]"

To use Podman, change the driver in the molecule/default/molecule.yml file as follows:

driver:
  name: podman

You can run all tests, which check for formatting, linting, and idempotency, with this command:

$ molecule test --parallel

Using the --parallel option is recommended, as it significantly reduces test runtime by running tests over multiple target containers.

You can also add additional tests to the molecule/default/verify.yml playbook if needed.

:guardsman: License


MIT (read more)

Informazioni sul progetto

Detects whether the target Ubuntu host is... a container or eventually localhost (and more).

Installa
ansible-galaxy install itnok.is_ubuntu
Licenza
mit
Download
6.8k
Proprietario