{"id":329308,"date":"2023-05-08T07:00:00","date_gmt":"2023-05-08T07:00:00","guid":{"rendered":"http:\/\/itteacheritfreelance.hk\/wordpress\/?guid=069436796908e4c62f5a52c03a9435e7"},"modified":"2023-05-08T07:00:00","modified_gmt":"2023-05-08T07:00:00","slug":"how-to-create-execution-environments-using-ansible-builder","status":"publish","type":"post","link":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/2023\/05\/08\/how-to-create-execution-environments-using-ansible-builder\/","title":{"rendered":"How to create execution environments using ansible-builder"},"content":{"rendered":"<p class=\"syndicated-attribution\"><meta name= \\\"keywords \\\" content= \\\"\u96fb\u5b50\u8a08\u7b97\u6a5f, \u6559\u80b2, IT \u96fb\u8166\u73ed,\u96fb\u8166\u88dc\u7fd2\uff0c \u96fb\u8166\u73ed\uff0c \u5bb6\u6559\uff0c \u79c1\u4eba\u8001\u5e2b\uff0c \u8cc7\u8a0a\u6280\u8853\uff0c \u7a0b\u5e8f\u8a2d\u8a08\uff0c \u96fb\u5b50\u8a08\u7b97\u6a5f\uff0c \u904a\u6232\uff0c \u860b\u679c\uff0c \u96fb\u5f71\uff0c \u8a08\u7b97\u6a5f\uff0c\u7de8\u78bc\uff0c Java\uff0c C\/C++\uff0c JavaScript\uff0c PHP\uff0c HTML\uff0c CSS\uff0c MySQL\uff0c mobile\uff0c Android\uff0c \u52d5\u6f2b\uff0c Python\uff0c teacher\uff0c \u88dc\u7fd2\uff0c \u96fb\u8166\u88dc\u7fd2 \u8cc7\u8a0a, \u7535\u5b50\u8ba1\u7b97\u673a, IT ,Game, apple, movie, Computer,student,Java,\u6559\u80b2, ,\u5b66\u751f, \u5b66\u4e60, learn, \u6559\u5b66,  Android, apple,anime, animation, \u4fe1\u606f\u6280\u672f, \u7a0b\u5e8f\u8bbe\u8ba1, \u79fb\u52a8\u7535\u8bdd, \u8cc7\u8a0a\u79d1\u6280,Game, Jeu, Juego,Call Of Duty ,\u4f7f\u547d\u53ec\u559a , \u6e38\u620f, \u7535\u5b50\u6e38\u620f,, \u591a\u4eba\u7535\u5b50\u6e38\u620f, \u7f51\u7edc\u6e38\u620f\uff0conline\uff0conline game, \u624b\u673a\u6e38\u620f, mobile \\\"><\/p>\n<p><span>How to create execution environments using ansible-builder<\/span><\/p>\n<p>The execution environment builder (aka Ansible Builder) is a part of <a href=\"https:\/\/developers.redhat.com\/products\/ansible\/\">Red Hat Ansible Automation Platform<\/a>. It is a command-line interface (CLI) tool for building and creating custom execution environments. The Ansible Builder project enables users to automate and accelerate the process of creating execution environments. This article will show you how to install and use the <a href=\"https:\/\/access.redhat.com\/documentation\/en-us\/red_hat_ansible_automation_platform\/2.1\/html\/ansible_builder_guide\/index\">execution environment builder<\/a> CLI tool.<\/p>\n<h2>Installing the execution environment builder<\/h2>\n<p>The execution environment builder makes it easier for Ansible Automation Platform content creators and administrators to build custom execution environments. They can use dependency information from various <a href=\"http:\/\/ansible.com\/products\/content-collections\">Ansible Content Collections<\/a>\u00a0and directly from the user.<\/p>\n<h3>Step 1: Install the execution environment builder tool<\/h3>\n<p>Install the execution environment builder tool from the Python Package Index (PyPI) by using the following command:<\/p>\n<pre>\n<code class=\"language-bash\">pip install ansible-builder<\/code><\/pre>\n<h3>Step 2: Access the ansible-builder subcommands<\/h3>\n<p>To access the subcommands of <code>ansible-builder<\/code>, run <code>build<\/code> and <code>create<\/code> commands to get help output.<\/p>\n<p>The <code>build<\/code> subcommand will build the execution environment using the definition file.<\/p>\n<pre>\n<code class=\"language-bash\">ansible-builder build \u2013help<\/code><\/pre>\n<p>It populates the build context and then uses Podman or Docker to create the execution environment image. The help output appears as follows:<\/p>\n<pre>\n<code class=\"language-bash\">usage: ansible-builder build [-h] [-t TAG] [--container-runtime {podman,docker}] [--build-arg BUILD_ARGS] [-f FILENAME] [-c BUILD_CONTEXT]\n                             [--output-filename {Containerfile,Dockerfile}] [-v {0,1,2,3}]\n\nCreates a build context (including a Containerfile) from an execution environment spec. The build context will be populated from the execution environment spec. After that, the specified container runtime podman\/docker will be invoked to build an image from that definition. After building the image, it can be used locally or published using the\nsupplied tag.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -t TAG, --tag TAG     The name for the container image being built (default: ansible-execution-env:latest)\n  --container-runtime {podman,docker}\n                        Specifies which container runtime to use (default: podman)\n  --build-arg BUILD_ARGS\n                        Build-time variables to pass to any podman or docker calls. Internally ansible-builder makes use of ANSIBLE_GALAXY_CLI_COLLECTION_OPTS, EE_BASE_IMAGE,\n                        EE_BUILDER_IMAGE.\n  -f FILENAME, --file FILENAME\n                        The definition of the execution environment (default: execution-environment.yml)\n  -c BUILD_CONTEXT, --context BUILD_CONTEXT\n                        The directory to use for the build context (default: context)\n  --output-filename {Containerfile,Dockerfile}\n                        Name of file to write image definition to (default depends on --container-runtime, Containerfile for podman and Dockerfile for docker)\n  -v {0,1,2,3}, --verbosity {0,1,2,3}\n                        Increase the output verbosity, for up to three levels of verbosity (invoked via \"--verbosity\" or \"-v\" followed by an integer ranging in value from 0 to\n                        3) (default: 2)\n<\/code><\/pre>\n<p>The <code>create<\/code> subcommand works similar to the <code>build<\/code> command.<\/p>\n<pre>\n<code class=\"language-bash\">ansible-builder create \u2013help<\/code><\/pre>\n<p>However, it will not build the execution environment image as you will see in the following output:<\/p>\n<pre>\n<code class=\"language-bash\">usage: ansible-builder build [-h] [-t TAG] [--container-runtime {podman,docker}] [--build-arg BUILD_ARGS] [-f FILENAME] [-c BUILD_CONTEXT]\n                             [--output-filename {Containerfile,Dockerfile}] [-v {0,1,2,3}]\n\nCreates a build context (including a Containerfile) from an execution environment spec. The build context will be populated from the execution environment spec. After that,\nthe specified container runtime podman\/docker will be invoked to build an image from that definition. After building the image, it can be used locally or published using the\nsupplied tag.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -t TAG, --tag TAG     The name for the container image being built (default: ansible-execution-env:latest)\n  --container-runtime {podman,docker}\n                        Specifies which container runtime to use (default: podman)\n  --build-arg BUILD_ARGS\n                        Build-time variables to pass to any podman or docker calls. Internally ansible-builder makes use of ANSIBLE_GALAXY_CLI_COLLECTION_OPTS, EE_BASE_IMAGE,\n                        EE_BUILDER_IMAGE.\n  -f FILENAME, --file FILENAME\n                        The definition of the execution environment (default: execution-environment.yml)\n  -c BUILD_CONTEXT, --context BUILD_CONTEXT\n                        The directory to use for the build context (default: context)\n  --output-filename {Containerfile,Dockerfile}\n                        Name of file to write image definition to (default depends on --container-runtime, Containerfile for podman and Dockerfile for docker)\n  -v {0,1,2,3}, --verbosity {0,1,2,3}\n                        Increase the output verbosity, for up to three levels of verbosity (invoked via \"--verbosity\" or \"-v\" followed by an integer ranging in value from 0 to\n                        3) (default: 2)\n<\/code><\/pre>\n<h3>Step 3: Populate the ansible-builder spec<\/h3>\n<p>Populate the <code>ansible-builder<\/code> spec to build the custom execution environment by running the following command:<\/p>\n<pre>\n<code class=\"language-bash\">mkdir project_directory && cd project_directory<\/code><\/pre>\n<p>Populate the <code>execution-environment.yml<\/code> file:<\/p>\n<pre>\n<code class=\"language-bash\">cat <<EOT >> execution-environment.yml\n---\nversion: 1\ndependencies:\n  galaxy: requirements.yml\nEOT\n\n<\/code><\/pre>\n<p>Create a <code>requirements.yml<\/code> file and populate the contents with the following:<\/p>\n<pre>\n<code class=\"language-bash\">cat <<EOT >> requirements.yml\n---\ncollections:\n  - name: servicenow.itsm\nEOT<\/code><\/pre>\n<p>Through the spec and requirements file, we ensure that execution environment builder will download the <strong>servicenow.itsm collection<\/strong> while building the execution environment. The default download location is <strong>galaxy.ansible.com<\/strong>. You can also point to an automation hub or your own hub instance in the spec file.<\/p>\n<h3>Step 4: Build the execution environment<\/h3>\n<p>Build the execution environment using the previously created files. Run the following command to create a new custom execution environment called <strong>custom-ee:<\/strong><\/p>\n<pre>\n<code class=\"language-bash\">ansible-builder build -v3 -t custom-ee<\/code><\/pre>\n<p>The <code>-v3<\/code> flag adds verbosity to the CLI run, and\u00a0<code>-t custom-ee<\/code> will tag your image with the name you provided.<\/p>\n<p>The output appears as follows:<\/p>\n<pre>\n<code class=\"language-bash\">Ansible Builder is building your execution environment image, \"custom-ee\".\nFile context\/_build\/requirements.yml will be created.\nRewriting Containerfile to capture collection requirements\nRunning command:\n  podman build -f context\/Containerfile -t custom-ee context\n[1\/3] STEP 1\/7: FROM registry.redhat.io\/ansible-automation-platform-21\/ee-minimal-rhel8:latest AS galaxy\n[1\/3] STEP 2\/7: ARG ANSIBLE_GALAXY_CLI_COLLECTION_OPTS=\n--> 88d9ea223d0\n[1\/3] STEP 3\/7: USER root\n--> 549f29055c2\n[1\/3] STEP 4\/7: ADD _build \/build\n--> 0d3e9515b12\n[1\/3] STEP 5\/7: WORKDIR \/build\n--> 3b290acf78c\n[1\/3] STEP 6\/7: RUN ansible-galaxy role install -r requirements.yml --roles-path \/usr\/share\/ansible\/roles\nSkipping install, no requirements found\n--> 8af36370e78\n[1\/3] STEP 7\/7: RUN ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path \/usr\/share\/ansible\/collections\nStarting galaxy collection install process\nProcess install dependency map\n\u2026\n\n<\/code><\/pre>\n<p>Run the following commands to check the image list:<\/p>\n<pre>\n<code class=\"language-bash\">podman images<\/code><\/pre>\n<p>The output appears as follows:<\/p>\n<pre>\n<code class=\"language-bash\">REPOSITORY                                                   TAG         IMAGE ID           CREATED                SIZE\nlocalhost\/custom-ee                                        latest      bfe6c40bad52    21 seconds ago      626 MB\n<\/code><\/pre>\n<h3>Step 5: Build a complex execution environment<\/h3>\n<p>To build a complex execution environment, go back into the project directory with the following command:<\/p>\n<pre>\n<code class=\"language-bash\">cd project_directory<\/code><\/pre>\n<p>Edit the <code>execution-environment.yml<\/code> file and add the following content:<\/p>\n<pre>\n<code class=\"language-bash\">cat <<EOT >> execution-environment.yml\n---\nversion: 1\ndependencies:\n  galaxy: requirements.yml\n  python: requirements.txt\n  system: bindep.txt\nadditional_build_steps:\n  prepend: |\n    RUN whoami\n    RUN cat \/etc\/os-release\n  append:\n    - RUN echo This is a post-install command!\n    - RUN ls -la \/etc\nEOT<\/code><\/pre>\n<p>We can see the following:<\/p>\n<ul>\n<li>Python requirements were added through the <strong>requirements.txt<\/strong> file, which will hold the pip dependencies.<\/li>\n<li>We added a <strong>bindep.txt<\/strong>, which will hold the rpm installs.<\/li>\n<li>Additional build steps that will run before (prepend) and after (append) the build steps.<\/li>\n<\/ul>\n<p>Now create a new file called <code>requirements.yml<\/code> and append the following content:<\/p>\n<pre>\n<code class=\"language-bash\">cat <<EOT >> requirements.yml\n---\n\ncollections:\n\n  - name: servicenow.itsm\n  - name: ansible.utils\nEOT<\/code><\/pre>\n<p>We added a new collection called <strong>ansible.utils<\/strong> alongside the <strong>servicenow.itsm<\/strong> file.<\/p>\n<p>Create a new file called <code>requirements.txt<\/code> and then append the following:<\/p>\n<pre>\n<code class=\"language-bash\">cat <<EOT >> requirements.txt\ngcp-cli\nncclient\nnetaddr\nparamiko\nEOT<\/code><\/pre>\n<p>This contains the <a href=\"https:\/\/developers.redhat.com\/topics\/python\">Python<\/a> requirements that need to be installed via pip.<\/p>\n<p>Create a new file called <code>bindep.txt<\/code> and then append the following:<\/p>\n<pre>\n<code class=\"language-bash\">cat <<EOT >> bindep.txt\nfindutils [compile platform:centos-8 platform:rhel-8]\ngcc [compile platform:centos-8 platform:rhel-8]\nmake [compile platform:centos-8 platform:rhel-8]\npython38-devel [compile platform:centos-8 platform:rhel-8]\npython38-cffi [platform:centos-8 platform:rhel-8]\npython38-cryptography [platform:centos-8 platform:rhel-8]\npython38-pycparser [platform:centos-8 platform:rhel-8]\nEOT<\/code><\/pre>\n<p>This file contains the rpm requirements needed to be installed using dnf.<\/p>\n<p>Run the following build:<\/p>\n<pre>\n<code class=\"language-bash\">ansible-builder build -v3 -t custom-ee<\/code><\/pre>\n<p>The output is as follows:<\/p>\n<pre>\n<code class=\"language-bash\">Ansible Builder is building your execution environment image, \"custom-ee\".\nFile context\/_build\/requirements.yml will be created.\nFile context\/_build\/requirements.txt will be created.\nFile context\/_build\/bindep.txt will be created.\nRewriting Containerfile to capture collection requirements\nRunning command:\n  podman build -f context\/Containerfile -t custom-ee context\n[1\/3] STEP 1\/7: FROM registry.redhat.io\/ansible-automation-platform-21\/ee-minimal-rhel8:latest AS galaxy\n[1\/3] STEP 2\/7: ARG ANSIBLE_GALAXY_CLI_COLLECTION_OPTS=\n--> Using cache 88d9ea223d01bec0d53eb7efcf0e76b5f7da0285a411f2ce0116fe9641cbc3a0\n--> 88d9ea223d0\n[1\/3] STEP 3\/7: USER root\n--> Using cache 549f29055c2f1ba0ef3f7c5dfdc67a40302ff0330af927adb94fbcd7b0b1e7b4\n--> 549f29055c2\n[1\/3] STEP 4\/7: ADD _build \/build\n--> 6b9ee91e773\n[1\/3] STEP 5\/7: WORKDIR \/build\n--> 5518e019f2d\n[1\/3] STEP 6\/7: RUN ansible-galaxy role install -r requirements.yml --roles-path \/usr\/share\/ansible\/roles\nSkipping install, no requirements found\n--> 60c1605d66c\n[1\/3] STEP 7\/7: RUN ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path \/usr\/share\/ansible\/collections\nStarting galaxy collection install process\nProcess install dependency map<\/code><\/pre>\n<p>You can check the context or <code>Containerfile<\/code> to see all the steps you took to build the execution environment. You can transfer the context directory to a different server and replicate the image creation via <code>docker<\/code> or <code>podman<\/code> commands.<\/p>\n<h2>Pushing the execution environment to a private automation hub<\/h2>\n<p>Log in to the <a href=\"https:\/\/www.ansible.com\/blog\/control-your-content-with-private-automation-hub\">private automation hub<\/a> by using the <code>podman<\/code> command:<\/p>\n<pre>\n<code class=\"language-bash\">podman login <automation hub url><\/code><\/pre>\n<p>Then tag the image before pushing it to the hub as follows:<\/p>\n<pre>\n<code class=\"language-bash\">podman tag localhost\/custom-ee <automation hub url>\/developers-bu-aap-builder<\/code><\/pre>\n<p>Finally, push it to the private automation hub as follows:<\/p>\n<pre>\n<code class=\"language-bash\">podman push <automation hub url>\/developers-bu-aap-builder<\/code><\/pre>\n<p>We can see the image pushed to the private automation hub in Figure 1:<\/p>\n<figure class=\"align-center\" role=\"group\">\n<div class=\"rhd-c-figure\">\n<article class=\"media media--type-image media--view-mode-article-content-full-width\">\n<div class=\"field field--name-image field--type-image field--label-hidden field__items\">\n  <a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/image_1.png\" data-featherlight=\"image\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_full_width_1440px_w\/public\/image_1.png?itok=AxLHdHot\" width=\"1440\" height=\"816\" alt=\"The private automation hub page showing multiple pushed execution environment images.\" typeof=\"foaf:Image\" \/><\/a>\n<\/div>\n<div class=\"field field--name-field-caption field--type-string field--label-hidden field__items\">\n<div class=\"rhd-c-caption field__item\">Figure 1: The private automation hub page showing multiple pushed execution environment images.<\/div>\n<\/div>\n<\/article>\n<\/div><figcaption class=\"rhd-c-caption\"><\/figcaption><\/figure>\n<h2>Continue your automation journey with Ansible Automation Platform<\/h2>\n<p><a href=\"https:\/\/developers.redhat.com\/products\/ansible\/getting-started\">Get started with Ansible Automation Platform<\/a>\u00a0by exploring <a href=\"https:\/\/developers.redhat.com\/products\/ansible\/getting-started\">interactive labs<\/a>. Check out Red Hat\u2019s hands-on labs for all skill levels to learn more. The\u00a0wide range of labs include\u00a0<a href=\"https:\/\/developers.redhat.com\/learn\/lessons\/linux-commands?intcmp=7013a0000026UTXAA2\">useful Linux commands<\/a>, <a href=\"https:\/\/developers.redhat.com\/learn\/installing-software-using-package-managers?intcmp=7013a0000026UTXAA2\">Install software using package managers<\/a>, and <a href=\"https:\/\/developers.redhat.com\/learn\/lessons\/deploying-containers-podman?intcmp=7013a0000026UTXAA2\">Deploying containers using container tools [podman]<\/a>. Try these labs to see your favorite products in action.\u00a0Ansible Automation Platform is also available as a managed offering on<a href=\"https:\/\/www.redhat.com\/en\/technologies\/management\/ansible\/azure\"> Microsoft Azure<\/a> and as a self-managed offering on <a href=\"https:\/\/www.redhat.com\/en\/technologies\/management\/ansible\/aws\">AWS<\/a>.<\/p>\n<p><span><span lang=\"\" about=\"https:\/\/developers.redhat.com\/user\/746973\" typeof=\"schema:Person\" property=\"schema:name\" datatype=\"\" xml:lang=\"\">rh-ee-tpaul<\/span><\/span><br \/>\n<span>Mon, 05\/08\/2023 &#8211; 07:00<\/span><br \/>\n<a href=\"https:\/\/developers.redhat.com\/author\/tathagata-paul-0\" hreflang=\"en\">Tathagata Paul<\/a><\/p>\n\n<p class=\"syndicated-attribution\"><figure class= \\\"wp-block-image alignnone \\\"><img src= \\\"http:\/\/itteacheritfreelance.hk\/test\/wordpress\/wp-content\/uploads\/2016\/05\/logo2-2.png\\\" alt=\\\"IT\u96fb\u8166\u88dc\u7fd2 java\u88dc\u7fd2 \u70ba\u5927\u5bb6\u914d\u5c0d\u96fb\u8166\u88dc\u7fd2,IT freelance, \u79c1\u4eba\u8001\u5e2b, PHP\u88dc\u7fd2,CSS\u88dc\u7fd2,XML,Java\u88dc\u7fd2,MySQL\u88dc\u7fd2,graphic design\u88dc\u7fd2,\u4e2d\u5c0f\u5b78ICT\u88dc\u7fd2,\u4e00\u5c0d\u4e00\u79c1\u4eba\u88dc\u7fd2\u548cFreelance\u81ea\u7531\u5de5\u4f5c\u914d\u5c0d\u3002\\\"\/><figcaption>\u7acb\u523b\u8a3b\u518a\u53ca\u5831\u540d\u96fb\u8166\u88dc\u7fd2\u8ab2\u7a0b\u5427!<\/figcaption><\/figure>\r\n<\/br>Find A Teacher Form:\r\n<\/br>https:\/\/docs.google.com\/forms\/d\/1vREBnX5n262umf4wU5U2pyTwvk9O-JrAgblA-wH9GFQ\/viewform?edit_requested=true#responses\r\n<\/br><\/br>Email:\r\n<\/br>public1989two@gmail.com<br><br><br><br><br><br><br>\r\n<a href=www.itsec.hk style=color:#FFFFFF;>www.itsec.hk<\/a><br>\r\n<a href=\\\"www.itsec.vip\\\" style=color:#FFFFFF;>www.itsec.vip<\/a><br>\r\n<a href=\\\"www.itseceu.uk\\\" style=color:#FFFFFF;>www.itseceu.uk<\/a><br><\/p>","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p><span>How to create execution environments using ansible-builder<\/span><\/p>\n<p>The execution environment builder (aka Ansible Builder) is a part of <a href=\"https:\/\/developers.redhat.com\/products\/ansible\/\">Red Hat Ansible Automation Platform<\/a>. It is a command-line interface (CLI) tool for building and creating custom execution environments. The Ansible Builder project enables users to automate and accelerate the process of creating execution environments. This article will show you how to install and use the <a href=\"https:\/\/access.redhat.com\/documentation\/en-us\/red_hat_ansible_automation_platform\/2.1\/html\/ansible_builder_guide\/index\">execution environment builder<\/a> CLI tool.<\/p>\n<h2>Installing the execution environment builder<\/h2>\n<p>The execution environment builder makes it easier for Ansible Automation Platform content creators and administrators to build custom execution environments. They can use dependency information from various <a href=\"http:\/\/ansible.com\/products\/content-collections\">Ansible Content Collections<\/a>\u00a0and directly from the user.<\/p>\n<h3>Step 1: Install the execution environment builder tool<\/h3>\n<p>Install the execution environment builder tool from the Python Package Index (PyPI) by using the following command:<\/p>\n<pre>\n<code class=\"language-bash\">pip install ansible-builder<\/code><\/pre>\n<h3>Step 2: Access the ansible-builder subcommands<\/h3>\n<p>To access the subcommands of <code>ansible-builder<\/code>, run <code>build<\/code> and <code>create<\/code> commands to get help output.<\/p>\n<p>The <code>build<\/code> subcommand will build the execution environment using the definition file.<\/p>\n<pre>\n<code class=\"language-bash\">ansible-builder build \u2013help<\/code><\/pre>\n<p>It populates the build context and then uses Podman or Docker to create the execution environment image. The help output appears as follows:<\/p>\n<pre>\n<code class=\"language-bash\">usage: ansible-builder build [-h] [-t TAG] [--container-runtime {podman,docker}] [--build-arg BUILD_ARGS] [-f FILENAME] [-c BUILD_CONTEXT]\n                             [--output-filename {Containerfile,Dockerfile}] [-v {0,1,2,3}]\n\nCreates a build context (including a Containerfile) from an execution environment spec. The build context will be populated from the execution environment spec. After that, the specified container runtime podman\/docker will be invoked to build an image from that definition. After building the image, it can be used locally or published using the\nsupplied tag.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -t TAG, --tag TAG     The name for the container image being built (default: ansible-execution-env:latest)\n  --container-runtime {podman,docker}\n                        Specifies which container runtime to use (default: podman)\n  --build-arg BUILD_ARGS\n                        Build-time variables to pass to any podman or docker calls. Internally ansible-builder makes use of ANSIBLE_GALAXY_CLI_COLLECTION_OPTS, EE_BASE_IMAGE,\n                        EE_BUILDER_IMAGE.\n  -f FILENAME, --file FILENAME\n                        The definition of the execution environment (default: execution-environment.yml)\n  -c BUILD_CONTEXT, --context BUILD_CONTEXT\n                        The directory to use for the build context (default: context)\n  --output-filename {Containerfile,Dockerfile}\n                        Name of file to write image definition to (default depends on --container-runtime, Containerfile for podman and Dockerfile for docker)\n  -v {0,1,2,3}, --verbosity {0,1,2,3}\n                        Increase the output verbosity, for up to three levels of verbosity (invoked via \"--verbosity\" or \"-v\" followed by an integer ranging in value from 0 to\n                        3) (default: 2)\n<\/code><\/pre>\n<p>The <code>create<\/code> subcommand works similar to the <code>build<\/code> command.<\/p>\n<pre>\n<code class=\"language-bash\">ansible-builder create \u2013help<\/code><\/pre>\n<p>However, it will not build the execution environment image as you will see in the following output:<\/p>\n<pre>\n<code class=\"language-bash\">usage: ansible-builder build [-h] [-t TAG] [--container-runtime {podman,docker}] [--build-arg BUILD_ARGS] [-f FILENAME] [-c BUILD_CONTEXT]\n                             [--output-filename {Containerfile,Dockerfile}] [-v {0,1,2,3}]\n\nCreates a build context (including a Containerfile) from an execution environment spec. The build context will be populated from the execution environment spec. After that,\nthe specified container runtime podman\/docker will be invoked to build an image from that definition. After building the image, it can be used locally or published using the\nsupplied tag.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -t TAG, --tag TAG     The name for the container image being built (default: ansible-execution-env:latest)\n  --container-runtime {podman,docker}\n                        Specifies which container runtime to use (default: podman)\n  --build-arg BUILD_ARGS\n                        Build-time variables to pass to any podman or docker calls. Internally ansible-builder makes use of ANSIBLE_GALAXY_CLI_COLLECTION_OPTS, EE_BASE_IMAGE,\n                        EE_BUILDER_IMAGE.\n  -f FILENAME, --file FILENAME\n                        The definition of the execution environment (default: execution-environment.yml)\n  -c BUILD_CONTEXT, --context BUILD_CONTEXT\n                        The directory to use for the build context (default: context)\n  --output-filename {Containerfile,Dockerfile}\n                        Name of file to write image definition to (default depends on --container-runtime, Containerfile for podman and Dockerfile for docker)\n  -v {0,1,2,3}, --verbosity {0,1,2,3}\n                        Increase the output verbosity, for up to three levels of verbosity (invoked via \"--verbosity\" or \"-v\" followed by an integer ranging in value from 0 to\n                        3) (default: 2)\n<\/code><\/pre>\n<h3>Step 3: Populate the ansible-builder spec<\/h3>\n<p>Populate the <code>ansible-builder<\/code> spec to build the custom execution environment by running the following command:<\/p>\n<pre>\n<code class=\"language-bash\">mkdir project_directory &amp;&amp; cd project_directory<\/code><\/pre>\n<p>Populate the <code>execution-environment.yml<\/code> file:<\/p>\n<pre>\n<code class=\"language-bash\">cat &gt; execution-environment.yml\n---\nversion: 1\ndependencies:\n  galaxy: requirements.yml\nEOT\n\n<\/code><\/pre>\n<p>Create a <code>requirements.yml<\/code> file and populate the contents with the following:<\/p>\n<pre>\n<code class=\"language-bash\">cat &gt; requirements.yml\n---\ncollections:\n  - name: servicenow.itsm\nEOT<\/code><\/pre>\n<p>Through the spec and requirements file, we ensure that execution environment builder will download the <strong>servicenow.itsm collection<\/strong> while building the execution environment. The default download location is <strong>galaxy.ansible.com<\/strong>. You can also point to an automation hub or your own hub instance in the spec file.<\/p>\n<h3>Step 4: Build the execution environment<\/h3>\n<p>Build the execution environment using the previously created files. Run the following command to create a new custom execution environment called <strong>custom-ee:<\/strong><\/p>\n<pre>\n<code class=\"language-bash\">ansible-builder build -v3 -t custom-ee<\/code><\/pre>\n<p>The <code>-v3<\/code> flag adds verbosity to the CLI run, and\u00a0<code>-t custom-ee<\/code> will tag your image with the name you provided.<\/p>\n<p>The output appears as follows:<\/p>\n<pre>\n<code class=\"language-bash\">Ansible Builder is building your execution environment image, \"custom-ee\".\nFile context\/_build\/requirements.yml will be created.\nRewriting Containerfile to capture collection requirements\nRunning command:\n  podman build -f context\/Containerfile -t custom-ee context\n[1\/3] STEP 1\/7: FROM registry.redhat.io\/ansible-automation-platform-21\/ee-minimal-rhel8:latest AS galaxy\n[1\/3] STEP 2\/7: ARG ANSIBLE_GALAXY_CLI_COLLECTION_OPTS=\n--&gt; 88d9ea223d0\n[1\/3] STEP 3\/7: USER root\n--&gt; 549f29055c2\n[1\/3] STEP 4\/7: ADD _build \/build\n--&gt; 0d3e9515b12\n[1\/3] STEP 5\/7: WORKDIR \/build\n--&gt; 3b290acf78c\n[1\/3] STEP 6\/7: RUN ansible-galaxy role install -r requirements.yml --roles-path \/usr\/share\/ansible\/roles\nSkipping install, no requirements found\n--&gt; 8af36370e78\n[1\/3] STEP 7\/7: RUN ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path \/usr\/share\/ansible\/collections\nStarting galaxy collection install process\nProcess install dependency map\n\u2026\n\n<\/code><\/pre>\n<p>Run the following commands to check the image list:<\/p>\n<pre>\n<code class=\"language-bash\">podman images<\/code><\/pre>\n<p>The output appears as follows:<\/p>\n<pre>\n<code class=\"language-bash\">REPOSITORY                                                   TAG         IMAGE ID           CREATED                SIZE\nlocalhost\/custom-ee                                        latest      bfe6c40bad52    21 seconds ago      626 MB\n<\/code><\/pre>\n<h3>Step 5: Build a complex execution environment<\/h3>\n<p>To build a complex execution environment, go back into the project directory with the following command:<\/p>\n<pre>\n<code class=\"language-bash\">cd project_directory<\/code><\/pre>\n<p>Edit the <code>execution-environment.yml<\/code> file and add the following content:<\/p>\n<pre>\n<code class=\"language-bash\">cat &gt; execution-environment.yml\n---\nversion: 1\ndependencies:\n  galaxy: requirements.yml\n  python: requirements.txt\n  system: bindep.txt\nadditional_build_steps:\n  prepend: |\n    RUN whoami\n    RUN cat \/etc\/os-release\n  append:\n    - RUN echo This is a post-install command!\n    - RUN ls -la \/etc\nEOT<\/code><\/pre>\n<p>We can see the following:<\/p>\n<ul>\n<li>Python requirements were added through the <strong>requirements.txt<\/strong> file, which will hold the pip dependencies.<\/li>\n<li>We added a <strong>bindep.txt<\/strong>, which will hold the rpm installs.<\/li>\n<li>Additional build steps that will run before (prepend) and after (append) the build steps.<\/li>\n<\/ul>\n<p>Now create a new file called <code>requirements.yml<\/code> and append the following content:<\/p>\n<pre>\n<code class=\"language-bash\">cat &gt; requirements.yml\n---\n\ncollections:\n\n  - name: servicenow.itsm\n  - name: ansible.utils\nEOT<\/code><\/pre>\n<p>We added a new collection called <strong>ansible.utils<\/strong> alongside the <strong>servicenow.itsm<\/strong> file.<\/p>\n<p>Create a new file called <code>requirements.txt<\/code> and then append the following:<\/p>\n<pre>\n<code class=\"language-bash\">cat &gt; requirements.txt\ngcp-cli\nncclient\nnetaddr\nparamiko\nEOT<\/code><\/pre>\n<p>This contains the <a href=\"https:\/\/developers.redhat.com\/topics\/python\">Python<\/a> requirements that need to be installed via pip.<\/p>\n<p>Create a new file called <code>bindep.txt<\/code> and then append the following:<\/p>\n<pre>\n<code class=\"language-bash\">cat &gt; bindep.txt\nfindutils [compile platform:centos-8 platform:rhel-8]\ngcc [compile platform:centos-8 platform:rhel-8]\nmake [compile platform:centos-8 platform:rhel-8]\npython38-devel [compile platform:centos-8 platform:rhel-8]\npython38-cffi [platform:centos-8 platform:rhel-8]\npython38-cryptography [platform:centos-8 platform:rhel-8]\npython38-pycparser [platform:centos-8 platform:rhel-8]\nEOT<\/code><\/pre>\n<p>This file contains the rpm requirements needed to be installed using dnf.<\/p>\n<p>Run the following build:<\/p>\n<pre>\n<code class=\"language-bash\">ansible-builder build -v3 -t custom-ee<\/code><\/pre>\n<p>The output is as follows:<\/p>\n<pre>\n<code class=\"language-bash\">Ansible Builder is building your execution environment image, \"custom-ee\".\nFile context\/_build\/requirements.yml will be created.\nFile context\/_build\/requirements.txt will be created.\nFile context\/_build\/bindep.txt will be created.\nRewriting Containerfile to capture collection requirements\nRunning command:\n  podman build -f context\/Containerfile -t custom-ee context\n[1\/3] STEP 1\/7: FROM registry.redhat.io\/ansible-automation-platform-21\/ee-minimal-rhel8:latest AS galaxy\n[1\/3] STEP 2\/7: ARG ANSIBLE_GALAXY_CLI_COLLECTION_OPTS=\n--&gt; Using cache 88d9ea223d01bec0d53eb7efcf0e76b5f7da0285a411f2ce0116fe9641cbc3a0\n--&gt; 88d9ea223d0\n[1\/3] STEP 3\/7: USER root\n--&gt; Using cache 549f29055c2f1ba0ef3f7c5dfdc67a40302ff0330af927adb94fbcd7b0b1e7b4\n--&gt; 549f29055c2\n[1\/3] STEP 4\/7: ADD _build \/build\n--&gt; 6b9ee91e773\n[1\/3] STEP 5\/7: WORKDIR \/build\n--&gt; 5518e019f2d\n[1\/3] STEP 6\/7: RUN ansible-galaxy role install -r requirements.yml --roles-path \/usr\/share\/ansible\/roles\nSkipping install, no requirements found\n--&gt; 60c1605d66c\n[1\/3] STEP 7\/7: RUN ansible-galaxy collection install $ANSIBLE_GALAXY_CLI_COLLECTION_OPTS -r requirements.yml --collections-path \/usr\/share\/ansible\/collections\nStarting galaxy collection install process\nProcess install dependency map<\/code><\/pre>\n<p>You can check the context or <code>Containerfile<\/code> to see all the steps you took to build the execution environment. You can transfer the context directory to a different server and replicate the image creation via <code>docker<\/code> or <code>podman<\/code> commands.<\/p>\n<h2>Pushing the execution environment to a private automation hub<\/h2>\n<p>Log in to the <a href=\"https:\/\/www.ansible.com\/blog\/control-your-content-with-private-automation-hub\">private automation hub<\/a> by using the <code>podman<\/code> command:<\/p>\n<pre>\n<code class=\"language-bash\">podman login <automation hub url><\/automation><\/code><\/pre>\n<p>Then tag the image before pushing it to the hub as follows:<\/p>\n<pre>\n<code class=\"language-bash\">podman tag localhost\/custom-ee <automation hub url>\/developers-bu-aap-builder<\/automation><\/code><\/pre>\n<p>Finally, push it to the private automation hub as follows:<\/p>\n<pre>\n<code class=\"language-bash\">podman push <automation hub url>\/developers-bu-aap-builder<\/automation><\/code><\/pre>\n<p>We can see the image pushed to the private automation hub in Figure 1:<\/p>\n<figure class=\"align-center\" role=\"group\">\n<div class=\"rhd-c-figure\">\n<article class=\"media media--type-image media--view-mode-article-content-full-width\">\n<div class=\"field field--name-image field--type-image field--label-hidden field__items\">\n  <a href=\"https:\/\/developers.redhat.com\/sites\/default\/files\/image_1.png\" data-featherlight=\"image\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/developers.redhat.com\/sites\/default\/files\/styles\/article_full_width_1440px_w\/public\/image_1.png?itok=AxLHdHot\" width=\"1440\" height=\"816\" alt=\"The private automation hub page showing multiple pushed execution environment images.\" typeof=\"foaf:Image\"><\/a>\n<\/div>\n<div class=\"field field--name-field-caption field--type-string field--label-hidden field__items\">\n<div class=\"rhd-c-caption field__item\">Figure 1: The private automation hub page showing multiple pushed execution environment images.<\/div>\n<\/div>\n<\/article>\n<\/div><figcaption class=\"rhd-c-caption\"><\/figcaption><\/figure>\n<h2>Continue your automation journey with Ansible Automation Platform<\/h2>\n<p><a href=\"https:\/\/developers.redhat.com\/products\/ansible\/getting-started\">Get started with Ansible Automation Platform<\/a>\u00a0by exploring <a href=\"https:\/\/developers.redhat.com\/products\/ansible\/getting-started\">interactive labs<\/a>. Check out Red Hat\u2019s hands-on labs for all skill levels to learn more. The\u00a0wide range of labs include\u00a0<a href=\"https:\/\/developers.redhat.com\/learn\/lessons\/linux-commands?intcmp=7013a0000026UTXAA2\">useful Linux commands<\/a>, <a href=\"https:\/\/developers.redhat.com\/learn\/installing-software-using-package-managers?intcmp=7013a0000026UTXAA2\">Install software using package managers<\/a>, and <a href=\"https:\/\/developers.redhat.com\/learn\/lessons\/deploying-containers-podman?intcmp=7013a0000026UTXAA2\">Deploying containers using container tools [podman]<\/a>. Try these labs to see your favorite products in action.\u00a0Ansible Automation Platform is also available as a managed offering on<a href=\"https:\/\/www.redhat.com\/en\/technologies\/management\/ansible\/azure\"> Microsoft Azure<\/a> and as a self-managed offering on <a href=\"https:\/\/www.redhat.com\/en\/technologies\/management\/ansible\/aws\">AWS<\/a>.<\/p>\n<p><span><span lang=\"\" about=\"https:\/\/developers.redhat.com\/user\/746973\" typeof=\"schema:Person\" property=\"schema:name\" datatype=\"\" xml:lang=\"\">rh-ee-tpaul<\/span><\/span><br \/>\n<span>Mon, 05\/08\/2023 &#8211; 07:00<\/span><br \/>\n<a href=\"https:\/\/developers.redhat.com\/author\/tathagata-paul-0\" hreflang=\"en\">Tathagata Paul<\/a><\/p>\n<\/div>","protected":false},"author":2032,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"slim_seo":{"title":"How to create execution environments using ansible-builder - ITTeacherITFreelance.hk","description":"How to create execution environments using ansible-builder The execution environment builder (aka Ansible Builder) is a part of Red Hat Ansible Automation Platf"},"footnotes":""},"categories":[10700],"tags":[],"_links":{"self":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/329308"}],"collection":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/users\/2032"}],"replies":[{"embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/comments?post=329308"}],"version-history":[{"count":1,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/329308\/revisions"}],"predecessor-version":[{"id":329309,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/posts\/329308\/revisions\/329309"}],"wp:attachment":[{"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/media?parent=329308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/categories?post=329308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itteacheritfreelance.hk\/wordpress\/index.php\/wp-json\/wp\/v2\/tags?post=329308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}