wiki/HowtoAWX.md
2024-01-22 19:12:21 +01:00

192 lines
6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
categories: web orchestration ansible
toc: yes
title: How to AWX
...
# How to AWX
* Documentation: [docs.ansible.com/ansible-tower/latest/html/userguide/overview.html](https://docs.ansible.com/ansible-tower/latest/html/userguide/overview.html)
* Repository: [github.com/ansible/awx](https://github.com/ansible/awx)
[AWX](https://www.ansible.com/community/awx-project) est une interface web et REST pour l'outil d'automatisation [ansible](Howtoansible).
## Installation
À 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.
### Kubernetes
Documentation: <https://ansible.readthedocs.io/projects/awx-operator/en/latest/installation/basic-install.html>
Déploiement de AWX Operator sur un cluster Kubernetes :
> 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 notre configuration :
~~~{.bash}
$ tree -L 3 awx
awx
├── kustomization.yaml
├── awx-instances
│   ├── demo
│   │   ├── awx-instance.yaml
│   │   ├── kustomization.yaml
│   │   ├── traefik-whitelist-middleware.yaml
│   │   └── treafik-ingressroute.yaml
│   └── kustomization.yaml
├── awx-operator
│   └── kustomization.yaml
└── traefik
├── kustomization.yaml
├── traefik-dashboard-ingressroute.yaml
├── traefik-helm-chart-config.yaml
├── traefik-helm-config.yaml.old
└── whitelist-middleware.yaml
~~~
* un fichier kustomize qui va assembler tout `awx/kustomization.yaml`
~~~{.yaml}
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ./traefik
- ./awx-operator
- ./awx-instances
~~~
* L'operateur `awx/awx-operator/kustomization.yaml ` qui va etre crée dans un namespace `awx`
~~~{.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
# Set the image tags to match the git version from above
images:
# le tag de l'image doit etre le meme que celui du release tag ci-dessus
- name: quay.io/ansible/awx-operator
newTag: 2.10.0
# Specifier le namespace de awx
namespace: awx
~~~
* Une instance...
~~~{.yaml}
# awx/awx-instances/demo/kustomization.yaml
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- awx-instance.yaml
- traefik-whitelist-middleware.yaml
- treafik-ingressroute.yaml
# awx/awx-instances/demo/awx-instance.yaml
apiVersion: awx.ansible.com/v1beta1
kind: AWX
metadata:
name: awx-demo
spec:
# service_type: nodeport
service_type: clusterip
~~~
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
~~~
~~~{.bash}
# voir ou en l'installation
$ kubectl -n awx logs -f deployments/awx-operator-controller-manager
# suivre le lancement d'instance(s)
$kubectl logs -n awx -f deployments/awx-operator-controller-manager -c awx-manager
# 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
~~~
### Docker (Déprécié)
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:
La documentation complète se situe sur [Github](https://github.com/ansible/awx/blob/devel/tools/docker-compose/README.md)
``
$ make docker-compose-build
$ make docker-compose
``
Suite a la complétion, on peut lancer dans un autre terminal:
``
$ docker exec tools_awx_1 make clean-ui ui-devel
``
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
```
$ pip3 install awxkit
```
### Doc
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
### Créer un nouvel admin
```
$ docker exec -ti tools_awx_1 awx-manage createsuperuser
```
### Utiliser un postgres externe
Il faut aller indiquer le postgres désiré dans les variables de `tools/docker-compose/inventory`