.. _example_300:

300 Module vbotka.freebsd.service
---------------------------------

.. contents::
   :local:
   :depth: 1

.. index:: single: module vbotka.freebsd.service; Example 300
.. index:: single: vbotka.freebsd.service; Example 300
.. index:: single: module community.general.ini; Example 300
.. index:: single: filter vbotka.freebsd.iocage; Example 300
.. index:: single: inventory vbotka.freebsd.iocage2; Example 300
.. index:: single: connection vbotka.freebsd.jailexec; Example 300

Use case
^^^^^^^^

Test the `module vbotka.freebsd.service`_.

Tree
^^^^

::

  shell> tree .
  .
  ├── ansible.cfg
  ├── hosts
  │   ├── 06_iocage2.yml
  │   └── 99_constructed.yml
  ├── iocage.ini
  ├── pb-test-01.yml
  ├── pb-test-02.yml
  ├── pb-test-03.yml
  ├── pb-test-04.yml
  ├── pb-test-05.yml
  ├── pb-test-06.yml
  └── pb-test-07.yml

Synopsis
^^^^^^^^

At all running jails in the managed node:

  * playbook ``pb-test-01.yml``: display sshd rcvar.
  * playbook ``pb-test-06.yml``: display sendmail rcvar.

At the managed node:

  * playbook ``pb-test-02.yml``: display sshd rcvar
  * playbook ``pb-test-03.yml``: display enabled services
  * playbook ``pb-test-04.yml``: display sshd status
  * playbook ``pb-test-05.yml``: display sshd commands synopsis
  * playbook ``pb-test-07.yml``: start apcupsd.

Requirements
^^^^^^^^^^^^

* `module vbotka.freebsd.service`_
* `filter vbotka.freebsd.iocage`_
* `inventory plugin vbotka.freebsd.iocage2`_
* `connection plugin vbotka.freebsd.jailexec`_
* running jails at the iocage host.

Notes
^^^^^

* Jail name doesn't work in iocage jails. Use JID instead.

.. seealso::

   * `man service`_

Jails at managed node
^^^^^^^^^^^^^^^^^^^^^

.. code-block:: console

   # iocage list -l

.. literalinclude:: out/out-01.txt
   :language: bash

ansible.cfg
^^^^^^^^^^^

.. literalinclude:: ansible.cfg
   :language: ini

Inventory iocage.ini
^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: iocage.ini
   :language: ini

hosts
^^^^^

.. literalinclude:: hosts/06_iocage2.yml
   :language: yaml
   :caption:

.. literalinclude:: hosts/99_constructed.yml
   :language: yaml
   :caption:

Display inventory
^^^^^^^^^^^^^^^^^

.. code-block:: console

   (env) > ansible-inventory -i hosts --graph

.. literalinclude:: out/out-02.txt
   :language: bash

Playbook pb-test-01.yml
^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: pb-test-01.yml
   :language: yaml

Playbook output - jails sshd rcvar
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

The key and value of ``rcvar`` is returned in 1) the attribute ``rcvar`` of the registered variable
``out.rcvar`` and in 2) the ``stdout``. Usually, you'll use the first option. The second option shows
how to use the filter``community.general.jc``.

.. code-block:: console

   (env) > ansible-playbook -i hosts pb-test-01.yml

.. literalinclude:: out/out-03.txt
   :language: yaml
   :force:

Playbook pb-test-02.yml
^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: pb-test-02.yml
   :language: yaml

Playbook output - create jid_rcvar
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: console

   (env) > ansible-playbook -i iocage.ini -e debug=true pb-test-02.yml

.. literalinclude:: out/out-04.txt
   :language: yaml
   :force:

Playbook pb-test-03.yml
^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: pb-test-03.yml
   :language: yaml

Playbook output - enabled services
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: console

   (env) > ansible-playbook -i iocage.ini -e debug=true pb-test-03.yml

.. literalinclude:: out/out-05.txt
   :language: yaml
   :force:

Playbook pb-test-04.yml
^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: pb-test-04.yml
   :language: yaml

Playbook output - sshd status
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: console

   (env) > ansible-playbook -i iocage.ini pb-test-04.yml

.. literalinclude:: out/out-06.txt
   :language: yaml
   :force:

Playbook pb-test-05.yml
^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: pb-test-05.yml
   :language: yaml

Playbook output - sshd commands synopsis
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: console

   (env) > ansible-playbook -i iocage.ini pb-test-05.yml

.. literalinclude:: out/out-07.txt
   :language: yaml
   :force:

Playbook pb-test-06.yml
^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: pb-test-06.yml
   :language: yaml

Playbook output - sendmail rcvar
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: console

   shell> ansible-playbook -i hosts pb-test-06.yml

.. literalinclude:: out/out-08.txt
   :language: yaml
   :force:

Playbook pb-test-07.yml
^^^^^^^^^^^^^^^^^^^^^^^

.. literalinclude:: pb-test-07.yml
   :language: yaml

Playbook output - start apcupsd
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: console

   (env) > ansible-playbook -i iocage.ini pb-test-07.yml

.. literalinclude:: out/out-09.txt
   :language: yaml
   :force:

.. _module vbotka.freebsd.service: https://galaxy.ansible.com/ui/repo/published/vbotka/freebsd/content/module/service/
.. _filter vbotka.freebsd.iocage: https://galaxy.ansible.com/ui/repo/published/vbotka/freebsd/content/filter/iocage/
.. _inventory plugin vbotka.freebsd.iocage2: https://galaxy.ansible.com/ui/repo/published/vbotka/freebsd/content/inventory/iocage2/
.. _connection plugin vbotka.freebsd.jailexec: https://galaxy.ansible.com/ui/repo/published/vbotka/freebsd/content/connection/jailexec/
.. _man service: https://man.freebsd.org/cgi/man.cgi?service(8)
