wiki/HowtoAWX.md

213 lines
6.6 KiB
Markdown
Raw Permalink Normal View History

2022-08-30 20:47:58 +02:00
---
categories: web orchestration ansible
toc: yes
title: How to AWX
...
# How to AWX
2022-08-30 21:10:41 +02:00
* Documentation: [docs.ansible.com/ansible-tower/latest/html/userguide/overview.html](https://docs.ansible.com/ansible-tower/latest/html/userguide/overview.html)
2022-08-30 21:04:51 +02:00
* Repository: [github.com/ansible/awx](https://github.com/ansible/awx)
2022-08-30 20:47:58 +02:00
[AWX](https://www.ansible.com/community/awx-project) est une interface web et REST pour l'outil d'automatisation [ansible](Howtoansible).
## Installation
2022-08-30 21:11:53 +02:00
À partir de 18.0 il est recommandé de l'installer à travers [AWX Operator](https://github.com/ansible/awx-operator) qui dépend de kubernetes. Il est aussi possible d'utiliser une image docker.
2022-08-30 20:47:58 +02:00
2024-01-18 20:01:32 +01:00
### Kubernetes
Documentation: <https://ansible.readthedocs.io/projects/awx-operator/en/latest/installation/basic-install.html>
Déploiement de AWX Operator sur un cluster Kubernetes :
2024-01-29 11:55:34 +01:00
* On utilise kustomize pour assembler et appliquer les configurations yaml Kubernetes.
2024-01-18 20:01:32 +01:00
2024-01-29 11:55:34 +01:00
* Il faut une storage class fonctionnelle dans le cluster.
Remarques :
* On peut aussi utiliser un chart helm pour l'opérateur uniquement : https://ansible.readthedocs.io/projects/awx-operator/en/latest/installation/helm-install-on-existing-cluster.html
* Si vous n'avez pas de cluster Kubernetes, on peut facilement en créer un cluster *mono-neud* avec k3s par exemple voir [HowtoK3s](/HowtoK3s.md)
Nous allons créer un dossier awx contenant la configuration pour l'opérateur, une instance et traefik (ingress) :
2024-01-18 20:01:32 +01:00
~~~{.bash}
2024-01-22 18:57:31 +01:00
$ tree -L 3 awx
2024-01-18 20:01:32 +01:00
awx
2024-01-22 18:57:31 +01:00
├── kustomization.yaml
├── awx-instances
│   ├── demo
│   │   ├── awx-instance.yaml
│   │   ├── kustomization.yaml
2024-01-29 11:55:34 +01:00
│   │   └── traefik-ingressroute.yaml
2024-01-22 18:57:31 +01:00
│   └── kustomization.yaml
2024-01-29 11:55:34 +01:00
└── awx-operator
   └── kustomization.yaml
2024-01-18 20:01:32 +01:00
~~~
2024-01-22 19:09:35 +01:00
* un fichier kustomize qui va assembler tout `awx/kustomization.yaml`
~~~{.yaml}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./awx-operator
- ./awx-instances
~~~
2024-01-29 11:55:34 +01:00
* L'opérateur `awx/awx-operator/kustomization.yaml ` qui va être créé dans le namespace `awx`
2024-01-18 20:01:32 +01:00
~~~{.yaml}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
# Prendre le dernier release tag : https://github.com/ansible/awx-operator/releases
- github.com/ansible/awx-operator/config/default?ref=2.10.0
2024-01-22 19:09:35 +01:00
# Set the image tags to match the git version from above
2024-01-18 20:01:32 +01:00
images:
2024-01-22 19:09:35 +01:00
# le tag de l'image doit etre le meme que celui du release tag ci-dessus
2024-01-18 20:01:32 +01:00
- name: quay.io/ansible/awx-operator
newTag: 2.10.0
# Specifier le namespace de awx
namespace: awx
~~~
2024-01-22 19:09:35 +01:00
* Une instance...
2024-01-18 20:01:32 +01:00
~~~{.yaml}
2024-01-22 19:09:35 +01:00
# awx/awx-instances/demo/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- awx-instance.yaml
2024-01-29 11:55:34 +01:00
- traefik-ingressroute.yaml
2024-01-22 19:09:35 +01:00
# awx/awx-instances/demo/awx-instance.yaml
2024-01-18 20:01:32 +01:00
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: awx-demo
spec:
2024-01-22 19:09:35 +01:00
service_type: clusterip
2024-01-29 11:55:34 +01:00
# awx/awx-instances/demo/traefik-ingressroute.yaml
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: demo-instance-awx
spec:
entryPoints:
- websecure
routes:
- kind: Rule
match: Host(`awx.chez-vous.org`)
services:
- kind: Service
name: awx-demo-service
port: 80
tls:
certResolver: letsencrypt
2024-01-18 20:01:32 +01:00
~~~
2024-01-29 11:55:34 +01:00
> on peut aussi configurer directement les paramètres de l'insgress dans le spec de l'instance, voir documentation : https://ansible.readthedocs.io/projects/awx-operator/en/latest/user-guide/network-and-tls-configuration.html
2024-01-18 20:01:32 +01:00
Lancer le Déploiement :
~~~{.bash}
$ kubectl apply -k awx
namespace/awx created
customresourcedefinition.apiextensions.k8s.io/awxbackups.awx.ansible.com created
customresourcedefinition.apiextensions.k8s.io/awxrestores.awx.ansible.com created
customresourcedefinition.apiextensions.k8s.io/awxs.awx.ansible.com created
serviceaccount/awx-operator-controller-manager created
role.rbac.authorization.k8s.io/awx-operator-awx-manager-role created
role.rbac.authorization.k8s.io/awx-operator-leader-election-role created
clusterrole.rbac.authorization.k8s.io/awx-operator-metrics-reader created
clusterrole.rbac.authorization.k8s.io/awx-operator-proxy-role created
rolebinding.rbac.authorization.k8s.io/awx-operator-awx-manager-rolebinding created
rolebinding.rbac.authorization.k8s.io/awx-operator-leader-election-rolebinding created
clusterrolebinding.rbac.authorization.k8s.io/awx-operator-proxy-rolebinding created
configmap/awx-operator-awx-manager-config created
service/awx-operator-controller-manager-metrics-service created
deployment.apps/awx-operator-controller-manager created
2024-01-22 18:57:31 +01:00
~~~
2024-01-18 20:01:32 +01:00
2024-01-29 11:55:34 +01:00
* Voir ou en est l'installation
2024-01-18 20:01:32 +01:00
~~~{.bash}
$ kubectl -n awx logs -f deployments/awx-operator-controller-manager
# suivre le lancement d'instance(s)
2024-01-29 11:55:34 +01:00
$ kubectl logs -n awx -f deployments/awx-operator-controller-manager -c awx-manager
2024-01-18 20:01:32 +01:00
# Récuperer le mot de passe d'une instance
$ kubectl get secret -n awx awx-demo-admin-password -o jsonpath="{.data.password}" | base64 --decode ; echo
~~~
2024-01-29 11:55:34 +01:00
Si tout se passe bien, on
2024-01-18 20:01:32 +01:00
### Docker (Déprécié)
2023-01-24 22:21:04 +01:00
Copier le dépôt sur le serveur a partir d'une version stable: https://github.com/ansible/awx/releases/tag
Il faudra installer les paquets suivants:
- `python3`
- `python3-venv`
- `python3-setuptools-scm`
- `python3-psycopg2`
- `ansible`
- `docker-compose`
Le dépôt devra appartenir a l'usager exécutant, il faut s'assurer que les programmes dans le dossier tools ont bien un droit dexécution. (Faire attention a noexec qui peut remonter jusqu'au conteneur dans certains cas)
Une fois les prérequis installée et les permissions bien appliquée, on peut continuer avec l'installation:
2023-01-24 22:23:27 +01:00
La documentation complète se situe sur [Github](https://github.com/ansible/awx/blob/devel/tools/docker-compose/README.md)
2023-01-24 22:21:04 +01:00
``
2023-01-24 22:23:27 +01:00
$ make docker-compose-build
$ make docker-compose
2023-01-24 22:21:04 +01:00
``
Suite a la complétion, on peut lancer dans un autre terminal:
``
2023-01-24 22:23:27 +01:00
$ docker exec tools_awx_1 make clean-ui ui-devel
2023-01-24 22:21:04 +01:00
``
On peut ensuite accéder a l'interface sur `https://localhost:8043/#/home`
### CLI
Une interface de ligne de commande peut aussi être installé directement sur l'hôte
2022-08-30 20:47:58 +02:00
```
2023-01-24 22:23:27 +01:00
$ pip3 install awxkit
2022-08-30 20:47:58 +02:00
```
2023-01-24 22:21:04 +01:00
### Doc
2022-08-30 20:47:58 +02:00
La documentation peut être installé en local
```
$ pip3 install sphinx sphinxcontrib-autoprogram
$ cd awxkit/awxkit/cli/docs
$ TOWER_HOST=https://awx.example.org TOWER_USERNAME=example TOWER_PASSWORD=secret make clean html
$ cd build/html/ && python -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ..
```
## Configuration
2023-01-24 22:21:04 +01:00
2023-01-24 22:23:27 +01:00
### Créer un nouvel admin
2023-01-24 22:21:04 +01:00
```
2023-01-24 22:23:27 +01:00
$ docker exec -ti tools_awx_1 awx-manage createsuperuser
2023-01-24 22:21:04 +01:00
```
### Utiliser un postgres externe
2023-01-24 22:23:27 +01:00
Il faut aller indiquer le postgres désiré dans les variables de `tools/docker-compose/inventory`