Debian Codegraph @

ansible_collections/dellemc/openmanage/docs/EXECUTION_ENVIRONMENT.md

raw symbols SCIP
1 # Using Ansible Automation Platform with Dell OpenManage Ansible Modules
2 Creating automation execution environments using the OpenManage Ansible Modules enables your automation teams to define, build, and update their automation environment themselves. Execution environments provide a common language to communicate automation dependency between automation developers, architects, and platform administrators.
3
4 In this tutorial, you will learn how to build the execution environment image, push the image to a registry, and then create the execution environment in Ansible Automation Platform.
5
6 ## Why Ansible Automation Platform over Galaxy
7
8 While Ansible Galaxy is good for testing the latest and greatest developer content, it is difficult to find the author who uploaded the content and if the content is supported. Whereas Ansible Automation Platform has bundles of modules, plugins, roles, and documentation from Red Hat. The Ansible Automation Platform provides the following benefits:
9
10 - Red Hat Certified content.
11 - The content can be directly used in your own Ansible playbooks.
12 - Private Ansible Automation hub can be used within the organization to publish and collaborate.
13 - Premium support enables you to get help directly from Red Hat if you have any issue with an official Red Hat collection or certified partner collection.
14 - Red Hat subscription provides free and unlimited access to any content available.
15
16
17 ## Workflow
18 In this tutorial, you will learn how to:
19 1. [Build execution environment image.](#build-execution-environment-image)
20 2. [Use Ansible Runner to verify the execution environment (Optional).](#use-ansible-runner-to-verify-the-execution-environment)
21 3. [Upload the execution environment to a registry.](#upload-the-execution-environment-to-a-registry)
22 4. [Create execution environment in Ansible Automation Platform.](#create-execution-environment-in-ansible-automation-platform)
23
24 ## Build execution environment image
25 Build a image with the required Ansible collections and libraries, and then upload it to a registry of your choice. In this tutorial, you will learn how to create a Podman image.
26
27 1. Create the following files in your local directory:
28 - *execution-environment.yml*
29 - *requirements.yml*
30 - *requirements.txt*
31 2. For installing OpenManage collections and their dependencies, copy the metadata from the [dellemc.openmanage](https://github.com/dell/dellemc-openmanage-ansible-modules) GitHub repository.
32
33 The following are the sample files:
34
35 **execution-environment.yml**
36
37 ```yaml
38 version: 3
39 dependencies:
40 galaxy: requirements.yml
41 python: requirements.txt
42 system: bindep.txt
43 ```
44
45 We can modify the execution environment file to configure as per your requirement based on the guidelines mentioned [here](https://docs.ansible.com/automation-controller/latest/html/userguide/ee_reference.html)
46
47
48 **requirements.yml**
49 ```yaml
50 collections:
51 - dellemc.openmanage
52 - ansible.utils
53 - ansible.windows
54 ```
55 Note: The content of the *requirements.yml* can be found [here](https://github.com/dell/dellemc-openmanage-ansible-modules/blob/collections/requirements.yml)
56
57 **requirements.txt**
58 ```yaml
59 omsdk
60 netaddr>=0.7.19
61 ```
62
63 Note: The content of the *requirements.txt* can be found [here](https://github.com/dell/dellemc-openmanage-ansible-modules/blob/collections/requirements.txt)
64
65 3. Build the Podman image using the following syntax:
66
67 `ansible-builder build -f <path>/execution-environment.yml --container-runtime=<container> -c build_context --tag <container.io>/<org_name or username>/<imagename>:<tag>`
68
69 In this tutorial, the following command is used to build the Docker image with the name "*execution-environment*".
70
71 ```yaml
72 $ ansible-builder build -f execution-environment.yml --container-runtime=podman -c build_context --tag quay.io/delluser/dell-openmanage-ee:<tag>
73
74 podman build -f context/Containerfile -t quay.io/delluser/dell-openmanage-ee context
75 Complete! The build context can be found at: /context
76 ```
77
78 ## Use Ansible Runner to verify the execution environment
79
80 **Note:** Using Ansible Runner to verify the execution environment is an optional step.
81
82 **Prerequisite**
83
84 Ensure to install Ansible Runner. For details on how to install Ansible Runner, see [https://ansible-runner.readthedocs.io/en/stable/install/](https://ansible-runner.readthedocs.io/en/stable/install/).
85
86 To verify the image using the Ansible Runner, do the following:
87
88 1. Create a folder structure as shown below:
89
90 ```yaml
91 runner-example/
92 ├── inventory
93 │ └── hosts
94 └── project
95 └── testplaybook.yml
96 ```
97
98 2. Create a host file with the following entries:
99
100 ```yaml
101 [idrac]
102 192.168.0.1
103
104 [idrac:vars]
105 ansible_python_interpreter=/usr/bin/python3.9
106 user=user
107 password=password
108 ```
109 3. Create a playbook.
110
111 ```yaml
112 - name: Get system inventory
113 hosts: idrac
114 gather_facts: false
115
116 tasks:
117 - name: Get system inventory.
118 dellemc.openmanage.idrac_system_info:
119 idrac_ip: "{{ inventory_hostname }}"
120 idrac_user: "{{ user }}"
121 idrac_password: "{{ password }}"
122 validate_certs: false
123 delegate_to: localhost
124 ```
125 4. Run the playbook using the following command:
126
127 ```yaml
128 ansible-runner run --process-isolation --process-isolation-executable podman --container-image quay.io/delluser/dell-openmanage-ee -p sysinfo.yml ./runner-example/ -v
129 No config file found; using defaults
130
131 PLAY [Get system inventory] ****************************************************
132
133 TASK [Get system inventory.] ***************************************************
134
135 ok: [192.168.0.1] => { ..sysdetails..}
136 META: ran handlers
137 META: ran handlers
138
139 PLAY RECAP *********************************************************************
140 192.168.0.1 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
141 ```
142 After the execution, a complete trace of execution information is saved in a directory structure as shown below:
143
144 ```yaml
145 # tree runner-example/
146 runner-example/
147 ├── artifacts
148 │ └── 53810baa-15de-4dd6-93a1-35a28eb89070
149 │ ├── ansible_version.txt
150 │ ├── collections.json
151 │ ├── command
152 │ ├── env.list
153 │ ├── fact_cache
154 │ ├── job_events
155 │ │ ├── 1-592da7d5-b64f-4121-a91f-b33f28f6b0da.json
156 │ │ ├── 2-0242ac11-0007-b479-84c9-000000000006.json
157 │ │ ├── 3-0242ac11-0007-b479-84c9-000000000008.json
158 │ │ ├── 4-6d132edf-994c-4bf4-b9b2-dd6fa6ba834f.json
159 │ │ ├── 5-22b7e7a4-5244-4d3c-bbb7-395980feaee1.json
160 │ │ └── 6-c7e089be-6494-4b6e-8379-cf435e108aa6.json
161 │ ├── rc
162 │ ├── status
163 │ ├── stderr
164 │ └── stdout
165 ├── inventory
166 │ └── hosts
167 └── project
168 └── sysinfo.yml
169 ```
170 ## Upload the execution environment to a registry
171
172 Now that you have built the image, you can upload the execution environment image to a registry. The following steps describe how to upload the image to a Docker registry. You can upload the image to a registry of your choice (https://quay.io or https://docker.io).
173
174 1. Log in to quay.io.
175 ```yaml
176 podman login quay.io
177 ```
178 2. To view the list of images, run the following command:
179
180 ```yaml
181 podman image list
182 ```
183 Output:
184
185 ```yaml
186 REPOSITORY TAG IMAGE ID CREATED SIZE
187 quay.io/delluser/dell-openmanage-ee latest 6ea6337881f5 36 seconds ago 908MB
188 <none> <none> bab8f0c1f372 3 hours ago 959MB
189 <none> <none> 26e61b6f31b6 3 hours ago 779MB
190 ```
191 3. Upload the image to the repository using the following command:
192
193 ```yaml
194 podman push quay.io/delluser/dell-openmanage-ee
195 ```
196 Output:
197
198 ```yaml
199 Using default tag: latest
200 The push refers to repository [quay.io/delluser/dell-openmanage-ee]
201 6a938007b4eb: Pushed
202 c1a7a8b69adb: Pushed
203 75f55eeed6f1: Pushed
204 7da4273e9d6b: Pushed
205 d8672b46fe52: Layer already exists
206 daf6e68722b8: Layer already exists
207 e258e2d51ae2: Layer already exists
208 134616f736b1: Layer already exists
209 34ac022ee9b6: Layer already exists
210 e7423a18eff2: Layer already exists
211 4d851e75ba42: Layer already exists
212 38adeed967d9: Layer already exists
213 78fc855ac59c: Layer already exists
214 d0f9b1e225dd: Layer already exists
215 5d4daec00137: Layer already exists
216 dd423f7aa20e: Layer already exists
217 1ce7e8b08eb8: Layer already exists
218 5fa5c1c78a8e: Layer already exists
219 e0808177f5c4: Layer already exists
220 aadc47c09f66: Layer already exists
221 101e6c349551: Layer already exists
222 latest: digest: sha256:7be5110235abf72e0547cac016a506d59313addefc445d35e5dff68edb0a9ad6 size: 4726
223 <none> 26e61b6f31b6 3 hours ago 779MB
224 ```
225
226 ## Create execution environment in Ansible Automation Platform
227 Now that you uploaded the image to a registry, you can now create the execution environment in Ansible Automation Platform.
228
229 ### Add execution environment
230
231 1. Log in to Ansible Automation Platform.
232 2. On the navigation pane, click **Administration > Execution Environments**.
233 3. On the **Execution Environments** page, click **Add**.
234 4. On the **Create new execution environment** page, enter the following details, and click **Save**.
235 - **Name**: Enter a name for the execution environment (required).
236 - **Image**: Enter the image name (required). The image name requires its full location (repo), the registry, image name, and version tag
237 - **Pull**: From the **Pull** drop-down list, select **Only pull the image if not present before running**.
238 - **Description**: optional.
239 - **Organization**: optionally assign the organization to specifically use this execution environment. To make the execution environment available for use across multiple organizations, leave this field blank.
240 - **Registry credential**: If the image has a protected container registry, provide the credential to access it.
241
242
243 ### Create Projects
244
245 A Project is a logical collection of Ansible playbooks.
246
247 1. On the navigation pane, click **Resources > Projects**.
248 2. On the **Projects** page, click **Add**.
249 3. On the **Create New Project** page, do the following, and click **Save**.
250 - From the **Source Control Credential Type** drop-down list, select the source control type. For example, you can select "GIT".
251 - In the **Source Control URL**, specify the source control URL. That is your repository link.
252
253 ### Create Credential Types
254 This tutorial uses a custom credential type. You can create credential types depending on your data center environment. For more information, see [Credential Types](https://docs.ansible.com/automation-controller/4.2.1/html/userguide/credentials.html#credential-types).
255
256 To create a credential type:
257
258 1. On the navigation pane, click **Administration > Credential Types**.
259 2. On the **Credential Types** page, click **Add**.
260 2. On the **Create Credential Types** page, enter the name, and then specify the **Input configuration** and **Injector configuration**.
261 3. Click **Save**.
262
263 This tutorial uses a custom credential type. The following are the input configuration and injector configuration used in this tutorial.
264
265 **Input configuration:**
266
267 ```yaml
268 fields:
269 - id: username
270 type: string
271 label: Username
272 - id: password
273 type: string
274 label: Password
275 secret: true
276 required:
277 - username
278 - password
279 ```
280
281 **Injector configuration:**
282
283 ```yaml
284 extra_vars:
285 user: '{{ username }}'
286 password: '{{ password }}'
287 ```
288 #### Create Credentials
289
290 1. On the navigation pane, click **Resources > Credentials**.
291 2. On the **Credentials** page, click **Add**.
292 3. On the **Create New Credential** page, enter the name of the credential and select the credential type.
293 4. Click **Save**.
294
295 **Note:** In this tutorial, the custom credential type that we created in the section [Create Credential Types](#create-credential-types) is used.
296
297 ## Create Inventories
298 1. On the navigation pane, click **Resources > Inventories**.
299 2. On the **Inventories** page, click **Add**.
300 3. On the **Create New Inventory** page, enter the details and click **Save**.
301 4. Add Groups and Hosts to the inventory.
302
303 ## Create Job Templates
304
305 1. On the navigation pane, click **Resources > Templates**.
306 2. On the **Templates** page, click **Add** and select the new job template.
307 3. On the **Create New Job Template** page, enter the name, inventory, project, execution environment, playbook, and credentials.
308 4. Click **Save**.
309 5. To run the template, on the **Details** page, click **Launch**.
310
311 To check the job status, on the navigation pane, select **Views > Jobs**. The following is a sample output in JSON.
312
313 ```yaml
314 PLAY [Get system inventory] ****************************************************
315
316 TASK [Get system inventory.] ***************************************************
317
318 ok: [192.168.0.1] => { ..sysdetails..}
319 META: ran handlers
320 META: ran handlers
321
322 PLAY RECAP *********************************************************************
323 192.168.0.1 : ok=1 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
324 ```
325
326 ## Troubleshoot
327 You can add an Ansible python interpreter to a Template or Inventory.
328
329 `ansible_python_interpreter: /usr/bin/python<version>`
330
331 ```yaml
332 ansible_python_interpreter: /usr/bin/python3.9
333 ```
334
335 ## Documentation references
336 - [https://www.redhat.com/en/technologies/management/ansible](https://www.redhat.com/en/technologies/management/ansible)
337 - [https://www.redhat.com/en/blog/what-ansible-automation-hub-and-why-should-you-use-it](https://www.redhat.com/en/blog/what-ansible-automation-hub-and-why-should-you-use-it)
338 - [https://www.ansible.com/blog/unlocking-efficiency-harnessing-the-capabilities-of-ansible-builder-3.0](https://www.ansible.com/blog/unlocking-efficiency-harnessing-the-capabilities-of-ansible-builder-3.0)