Roles
This playbook is designed to fetch a device's/virtual machine's rendered configuration from NetBox and run an ansible role that is mapped to the NetBox device/virtual machine role.
Playbook AWX / Ansible Automation Platform Template Import
This playbook includes the AWX feature where it imports the playbook as job templates in to AWX / Ansible Automation Platform. The following job templates that will be created:
-
Playbook/Role/Ansible Setup a hosts configured role
-
Playbook/Role/Helm Chart Deploy a Helm Chart
-
Playbook/Role/Kubernetes Manifest Deploy a Kubernetes Manifest
Requirements
-
The inventory must contain the following variables:
role
andserial
which the value ofserial
must match those within NetBox.Tip
The
netbox.netbox.nb_inventory
inventory plugin does contain the required variables. -
NetBox has been setup with the required custom fields.
Info
You can use our Ansible Role
nofusscomputing.kubernetes.kubernetes_netbox
to setup NetBox with the required fields. See Documentation for more info. -
Rendered configuration contains the required variables for the Ansible Role being used.
Info
We provide publicly accessible templates for our roles, should you wish not to create your own.
Usage
This playbook is broken up into different role types, they are:
-
Ansible Role
-
Helm Chart
-
Kubernetes Manifest
Ansible Role
- job tag
ansible_role
This playbook requires the following variables be set.
role_map: # Mandatory, Dict.
kubernetes_node: # Mandatory, String. Netbox device/Virtual Machine role slug
name: nofusscomputing.kubernetes.nfc_kubernetes # Mandatory, String. Name of the Ansible Role that will be run
tasks_from: main # Optional, String. Name of the task file within the role that will be used.
Environmental variables NETBOX_API
and NETBOX_TOKEN
, must be set for the url (with protocol) and token to access NetBox.
The remaining required variables that must be set are those that are required by the Ansible Role. These variables must be part of the device/virtual machine rendered configuration.
Helm Chart
On the Ansible Controller, helm must be installed as must the PyYaml Python module.
- job tag
helm_chart
This playbook requires the following variables be set.
role_map: # Mandatory, Dict.
nginx_ingress: # Mandatory, String. Chart Name
name: nginx # Mandatory, String. Helm deployment name
repo:
name: nginx # Mandatory, String. Name to give the repository
url: https://kubernetes.github.io/ingress-nginx # Mandatory, String. Helm Chart repository URL
chart: ingress-nginx # Mandatory, String. Name of the chart withing the helm repo.
version: '4.8.2' # Mandatory, String. Chart version to deploy
namespace: ingress # Optional, String. Kubernetes namespace to deploy chart to.
create_namespace: true # Optional, String. Create Namespoace?
release_values: # Optional, Dict. Chart Values.
# Optional, String. Template filename for chart values
template_file: "{{ inventory_dir + '/../../templates/helm-chart-values/nginx.yaml.j2'}}"
Tip
AS a helm repository can contain multiple helm charts, keeping the repo
dictionary the same across different helm role is recommended so that you don't end up with multiple helm repositories pointing to the same content.
The following environmental variables must be set so that the ansible controller can connect to the kubernetes host:
K8S_AUTH_HOST
,K8S_AUTH_API_KEY
,K8S_AUTH_SSL_CA_CERT
and optionallyK8S_AUTH_VERIFY_SSL
or
K8S_AUTH_KUBECONFIG
The remaining required variables that must be set are those that are required by the template file if specified. These variables must be part of the device/virtual machine rendered configuration or included in the Ansible Inventory.
Kubernetes Manifest
On the Ansible Controller, kubectl must be installed as must the PyYaml and jsonpatch Python module.
- job tag
kubernetes_manifest
This playbook requires the following variables be set.
role_map: # Mandatory, Dict.
ingress_my_website: # Mandatory, String. Chart Name
name: The ingress for my website # Mandatory, String. Arbitrary name.
state: present # Optional, String. present or absent
# Mandatory, String. Template filename containing the kubernetes manifest.
template: "{{ inventory_dir + '/../../templates/kubernetes/my_website.yaml.j2'}}"
The following environmental variables must be set so that the ansible controller can connect to the kubernetes host:
K8S_AUTH_HOST
,K8S_AUTH_API_KEY
,K8S_AUTH_SSL_CA_CERT
and optionallyK8S_AUTH_VERIFY_SSL
or
K8S_AUTH_KUBECONFIG
The remaining required variables that must be set are those that are required by the template file if specified. These variables must be part of the device/virtual machine rendered configuration or included in the Ansible Inventory.
Workflow
This playbook has the following workflow:
-
Confirm environmental variables
NETBOX_API
andNETBOX_TOKEN
are set -
Fetching of the host (Device / Virtual Machine) ID from NetBox using
inventory_hostname
andserial
as the filter -
Fetching of the hosts rendered config
-
Saves the rendered config to a tmp file
-
Load tmp file (load variables into
hostvars
) -
Removes tmp file
-
Variable Validation
- Role
kubernetes_node
Confirms required variables are set
- Role
-
Runs the role as specified in
role_map
Playbook Definition
role.yaml | |
---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
|
About:
This page forms part of our Project Ansible Playbooks.
Page Metadata
Version: ToDo: place files short git commit hereDate Created: 2024-04-24
Date Edited: 2024-04-24
Contribution:
Would You like to contribute to our Ansible Playbooks project? You can assist in the following ways:
- Edit This Page If there is a mistake or a way you can improve it.
- Add a Page to the Manual if you would like to add an item to our manual
- Raise an Issue if there is something about this page you would like to improve, and git is unfamiliar to you.
ToDo: Add the page list of contributors