Skip to content

Commit 42019b8

Browse files
Restore community ee content (#1852) (#1859)
* restore community ee content This PR restores the docs about community execution environments from the ecosystem docsite. Please see the forum post for more info about this change: https://forum.ansible.com/t/moving-the-community-ee-content-to-package-docs/8239 * Update docs/docsite/rst/getting_started_ee/introduction.rst Co-authored-by: Andrew Klychkov <[email protected]> * Update docs/docsite/rst/getting_started_ee/introduction.rst Co-authored-by: Andrew Klychkov <[email protected]> * Update docs/docsite/rst/getting_started_ee/run_community_ee_image.rst Co-authored-by: Andrew Klychkov <[email protected]> * formatting nits --------- Co-authored-by: Andrew Klychkov <[email protected]> (cherry picked from commit 2043e2e) Co-authored-by: Don Naro <[email protected]>
1 parent 48d7d99 commit 42019b8

File tree

10 files changed

+334
-17
lines changed

10 files changed

+334
-17
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.. _building_execution_environment:
2+
3+
*****************************************
4+
Building your first Execution Environment
5+
*****************************************
6+
7+
We are going to build an EE that represents an Ansible control node containing standard packages such as ``ansible-core`` and Python in addition to an Ansible collection (``community.postgresql``) and its dependency (the ``psycopg2-binary`` Python connector).
8+
9+
To build your first EE:
10+
11+
#. Create a project folder on your filesystem.
12+
13+
.. code-block:: bash
14+
15+
mkdir my_first_ee && cd my_first_ee
16+
17+
#. Create a ``execution-environment.yml`` file that specifies dependencies to include in the image.
18+
19+
.. literalinclude:: yaml/execution-environment.yml
20+
:language: yaml
21+
22+
> The `psycopg2-binary` Python package is included in the `requirements.txt` file for the collection.
23+
> For collections that do not include `requirements.txt` files, you need to specify Python dependencies explicitly.
24+
> See the `Ansible Builder documentation <https://ansible-builder.readthedocs.io/en/stable/definition/>`_ for details.
25+
26+
#. Build a EE container image called ``postgresql_ee``.
27+
28+
If you use docker, add the ``--container-runtime docker`` argument.
29+
30+
.. code-block:: bash
31+
32+
ansible-builder build --tag postgresql_ee
33+
34+
#. List container images to verify that you built it successfully.
35+
36+
.. code-block:: bash
37+
38+
podman image list
39+
40+
localhost/postgresql_ee latest 2e866777269b 6 minutes ago 1.11 GB
41+
42+
You can verify the image you created by inspecting the ``Containerfile`` or ``Dockerfile`` in the ``context`` directory to view its configuration.
43+
44+
.. code-block:: bash
45+
46+
less context/Containerfile
47+
48+
You can also use Ansible Navigator to view detailed information about the image.
49+
50+
Run the `ansible-navigator` command, type ``:images`` in the TUI, and then choose ``postgresql_ee``.
51+
52+
Proceed to :ref:`running_custom_execution_environment` and test the EE you just built.
53+
54+
.. seealso::
55+
56+
`Running a local container registry for Execution Environments <https://forum.ansible.com/t/running-a-local-container-registry-for-execution-environments/206>`_
57+
This guide in the Ansible community forum explains how to set up a local registry for your Execution Environment images.

docs/docsite/rst/getting_started_ee/index.rst

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,34 @@
44
Getting started with Execution Environments
55
*******************************************
66

7-
Execution Environments (EEs) are Ansible control nodes packaged as container images.
7+
You can run Ansible automation in containers, like any other modern software application.
8+
Ansible uses container images known as Execution Environments (EE) that act as control nodes.
89
EEs remove complexity to scale out automation projects and make things like deployment operations much more straightforward.
910

10-
EEs provide you with:
11+
An Execution Environment image contains the following packages as standard:
1112

12-
* Software dependency isolation
13-
* Portability across teams and environments
14-
* Separation from other automation content and tooling
13+
* ``ansible-core``
14+
* ``ansible-runner``
15+
* Python
16+
* Ansible content dependencies
1517

16-
You can use Ansible community EEs to get up and running.
17-
Or you can easily build and deploy custom EEs with whatever packages and Ansible community collections you need for your project.
18+
In addition to the standard packages, an EE can also contain:
1819

19-
Visit `Getting started with Execution Environments <https://ansible.readthedocs.io/en/latest/getting_started_ee/index.html>`_ in the Ansible ecosystem documentation.
20+
* one or more Ansible collections and their dependencies
21+
* other custom components
2022

21-
Ansible ecosystem
22-
-----------------
23+
This getting started guide shows you how to build and test a simple Execution Environment.
24+
The resulting container image represents an Ansible control node that contains:
2325

24-
Using EEs with projects in the Ansible ecosystem lets you expand automation to lots of use cases:
26+
* standard EE packages
27+
* ``community.postgresql`` collection
28+
* ``psycopg2-binary`` Python package
2529

26-
* `Ansible Builder <https://ansible.readthedocs.io/projects/builder/en/latest/>`_
27-
* `Ansible Navigator <https://ansible.readthedocs.io/projects/navigator/>`_
28-
* `Ansible AWX <https://ansible.readthedocs.io/projects/awx/en/latest/userguide/execution_environments.html#use-an-execution-environment-in-jobs>`_
29-
* `Ansible Runner <https://ansible.readthedocs.io/projects/runner/en/stable/>`_
30-
* VS Code `Ansible <https://marketplace.visualstudio.com/items?itemName=redhat.ansible>`_ and `Dev Containers <https://code.visualstudio.com/docs/devcontainers/containers>`_ extensions
30+
.. toctree::
31+
:maxdepth: 1
3132

32-
Visit the `Ansible ecosystem documentation <https://ansible.readthedocs.io/en/latest/index.html>`_ to find How Tos and tutorials for using EEs with Ansible projects.
33+
introduction
34+
setup_environment
35+
build_execution_environment
36+
run_execution_environment
37+
run_community_ee_image
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
.. _introduction_execution_environment:
2+
3+
**************************************
4+
Introduction to Execution Environments
5+
**************************************
6+
7+
Ansible Execution Environments aim to resolve complexity issues and provide all the benefits you can get from containerization.
8+
9+
Reducing complexity
10+
===================
11+
12+
There are three main areas where EEs can reduce complexity:
13+
14+
* software dependencies
15+
* portability
16+
* content separation
17+
18+
Dependencies
19+
------------
20+
21+
Software applications typically have dependencies, and Ansible is no exception.
22+
These dependencies can include software libraries, configuration files or other services, to name a few.
23+
24+
Traditionally, administrators install application dependencies on top of an operating system using packaging management tools such as RPM or Python-pip.
25+
The major drawback of such an approach is that an application might require versions of dependencies different from those provided by default.
26+
For Ansible, a typical installation consists of `ansible-core` and a set of Ansible collections.
27+
Many of them have dependencies for the plugins, modules, roles and playbooks they provide.
28+
29+
The Ansible collections can depend on the following pieces of software and their versions:
30+
31+
* ``ansible-core``
32+
* Python
33+
* Python packages
34+
* System packages
35+
* Other Ansible collections
36+
37+
The dependencies have to be installed and sometimes can conflict with each other.
38+
39+
One way to **partially** resolve the dependency issue is to use Python virtual environments on Ansible control nodes.
40+
However, applied to Ansible, virtual environments have drawbacks and natural limitations.
41+
42+
Portability
43+
-----------
44+
45+
An Ansible user writes content for Ansible locally and wants to leverage the container technology to make their automation runtimes portable, shareable and easily deployable to testing and production environments.
46+
47+
Content separation
48+
------------------
49+
50+
In situations when there is an Ansible control node or a tool such as Ansible AWX/Controller used by several users, they might want separate
51+
their content to avoid configuration and dependency conflicts.
52+
53+
Ansible tooling for EEs
54+
=======================
55+
56+
Projects in the Ansible ecosystem also provide several tools that you can use with EEs, such as:
57+
58+
* `Ansible Builder <https://ansible-builder.readthedocs.io/en/stable/>`_
59+
* `Ansible Navigator <https://ansible-navigator.readthedocs.io/>`_
60+
* `Ansible AWX <https://ansible.readthedocs.io/projects/awx/en/latest/userguide/execution_environments.html#use-an-execution-environment-in-jobs>`_
61+
* `Ansible Runner <https://ansible-runner.readthedocs.io/en/stable/>`_
62+
* `VS Code Ansible <https://marketplace.visualstudio.com/items?itemName=redhat.ansible>`_
63+
* `Dev Containers extensions <https://code.visualstudio.com/docs/devcontainers/containers>`_
64+
65+
Ready to get started with EEs? Proceed to :ref:`setting_up_ee_environment`.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
.. _running_community_execution_environment:
2+
3+
*******************************************
4+
Running Ansible with the community EE image
5+
*******************************************
6+
7+
You can run ansible without the need to build a custom EE using community images.
8+
9+
Use the ``community-ee-minimal`` image that includes only ``ansible-core`` or the ``community-ee-base`` image that also includes several base collections.
10+
Run the following command to see the collections included in the ``community-ee-base`` image:
11+
12+
.. code-block:: bash
13+
14+
ansible-navigator collections --execution-environment-image ghcr.io/ansible-community/community-ee-base:latest
15+
16+
Run the following Ansible ad-hoc command against localhost inside the ``community-ee-minimal`` container:
17+
18+
.. code-block:: bash
19+
20+
ansible-navigator exec "ansible localhost -m setup" --execution-environment-image ghcr.io/ansible-community/community-ee-minimal:latest --mode stdout
21+
22+
Now, create a simple test playbook and run it against ``localhost`` inside the container:
23+
24+
.. literalinclude:: yaml/test_localhost.yml
25+
:language: yaml
26+
27+
.. code-block:: bash
28+
29+
ansible-navigator run test_localhost.yml --execution-environment-image ghcr.io/ansible-community/community-ee-minimal:latest --mode stdout
30+
31+
.. seealso::
32+
33+
* :ref:`building_execution_environment`
34+
* :ref:`running_custom_execution_environment`
35+
* `Ansible Navigator documentation <https://ansible-navigator.readthedocs.io/>`_
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
.. _running_custom_execution_environment:
2+
3+
***************
4+
Running your EE
5+
***************
6+
7+
You can run your EE on the command line against ``localhost`` or a remote target using ``ansible-navigator``.
8+
9+
> There are other tools besides ``ansible-navigator`` you can run EEs with.
10+
11+
Run against localhost
12+
=====================
13+
14+
#. Create a ``test_localhost.yml`` playbook.
15+
16+
.. literalinclude:: yaml/test_localhost.yml
17+
:language: yaml
18+
19+
#. Run the playbook inside the ``postgresql_ee`` EE.
20+
21+
.. code-block:: bash
22+
23+
ansible-navigator run test_localhost.yml --execution-environment-image postgresql_ee --mode stdout --pull-policy missing --container-options='--user=0'
24+
25+
You may notice the facts being gathered are about the container and not the developer machine.
26+
This is because the ansible playbook was run inside the container.
27+
28+
Run against a remote target
29+
===========================
30+
31+
Before you start, ensure you have the following:
32+
33+
* At least one IP address or resolvable hostname for a remote target.
34+
* Valid credentials for the remote host.
35+
* A user with `sudo` permissions on the remote host.
36+
37+
Execute a playbook inside the ``postgresql_ee`` EE against a remote host machine as in the following example:
38+
39+
#. Create a directory for inventory files.
40+
41+
.. code-block:: bash
42+
43+
mkdir inventory
44+
45+
#. Create the ``hosts.yml`` inventory file in the ``inventory`` directory.
46+
47+
.. literalinclude:: yaml/hosts.yml
48+
:language: yaml
49+
50+
#. Create a ``test_remote.yml`` playbook.
51+
52+
.. literalinclude:: yaml/test_remote.yml
53+
:language: yaml
54+
55+
#. Run the playbook inside the ``postgresql_ee`` EE.
56+
57+
Replace ``student`` with the appropriate username.
58+
Some arguments in the command can be optional depending on your target host authentication method.
59+
60+
.. code-block:: bash
61+
62+
ansible-navigator run test_remote.yml -i inventory --execution-environment-image postgresql_ee:latest --mode stdout --pull-policy missing --enable-prompts -u student -k -K
63+
64+
.. seealso::
65+
66+
`Execution Environment Definition <https://ansible-builder.readthedocs.io/en/stable/definition/>`_
67+
Provides information about the about Execution Environment definition file and available options.
68+
`Ansible Builder CLI usage <https://ansible-builder.readthedocs.io/en/stable/usage/>`_
69+
Provides details about using Ansible Builder.
70+
`Ansible Navigator documentation <https://ansible-navigator.readthedocs.io/>`_
71+
Provides details about using Ansible Navigator.
72+
`Running a local container registry for EEs <https://forum.ansible.com/t/running-local-container-registry-for-execution-environments/206>`_
73+
This guide in the Ansible community forum explains how to set up a local registry for your Execution Environment images.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
.. _setting_up_ee_environment:
2+
3+
***************************
4+
Setting up your environment
5+
***************************
6+
7+
Complete the following steps to set up a local environment for your first Execution Environment:
8+
9+
#. Ensure the following packages are installed on your system:
10+
11+
* ``podman`` or ``docker``
12+
* ``python3``
13+
14+
If you use the DNF package manager, install these prerequisites as follows:
15+
16+
.. code-block:: bash
17+
18+
sudo dnf install -y podman python3
19+
20+
#. Install ``ansible-navigator``:
21+
22+
.. code-block:: bash
23+
24+
pip3 install ansible-navigator
25+
26+
Installing ``ansible-navigator`` lets you run EEs on the command line.
27+
It includes the ``ansible-builder`` package to build EEs.
28+
29+
If you want to build EEs without testing, install only ``ansible-builder``:
30+
31+
.. code-block:: bash
32+
33+
pip3 install ansible-builder
34+
35+
#. Verify your environment with the following commands:
36+
37+
.. code-block:: bash
38+
39+
ansible-navigator --version
40+
ansible-builder --version
41+
42+
Ready to build an EE in a few easy steps? Proceed to :ref:`building_execution_environment`.
43+
44+
Want to try an EE without having to build one? Proceed to :ref:`running_community_execution_environment`.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: 3
2+
3+
images:
4+
base_image:
5+
name: quay.io/fedora/fedora:latest
6+
7+
dependencies:
8+
ansible_core:
9+
package_pip: ansible-core
10+
ansible_runner:
11+
package_pip: ansible-runner
12+
system:
13+
- openssh-clients
14+
- sshpass
15+
galaxy:
16+
collections:
17+
- name: community.postgresql
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
all:
2+
hosts:
3+
192.168.0.2 # Replace with the IP of your target host
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- name: Gather and print local facts
2+
hosts: localhost
3+
become: true
4+
gather_facts: true
5+
tasks:
6+
7+
- name: Print facts
8+
ansible.builtin.debug:
9+
var: ansible_facts
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
- name: Gather and print facts
2+
hosts: all
3+
become: true
4+
gather_facts: true
5+
tasks:
6+
7+
- name: Print facts
8+
ansible.builtin.debug:
9+
var: ansible_facts

0 commit comments

Comments
 (0)