Notes Tower AWX AAP Ansible Automation Platform

Voir :

AAP Ansible Automation Platform - Credentials - exports - decrypt

AAP managed hosts Python requirements

Notes Ansible ansible-navigator

Ansible Docker Execution Environment

Ansible AWX - Tower Cli

Install

Voir :

https://developers.redhat.com/articles/2023/01/01/how-install-red-hat-ansible-automation-platform-rhel-9

shell_plus

Voir :

https://django-extensions.readthedocs.io/en/latest/shell_plus.html

AAP Ansible Automation Platform - Credentials - exports - decrypt

shell_plus avec IPython

Install

Voir aussi :

/var/lib/awx/venv/awx/bin/pip install graphviz

https://gist.github.com/AlanCoding/bca128a1b391e28819f4020eb9b6536e

python3.9 -m venv ipython pip install ipython cp -a venv/ venv2/ rsync -axv --exclude "*.pyc" --exclude "__pycache__" ipython/ venv2/awx/ rsync -axv --exclude "*.pyc" --exclude "__pycache__" venv/awx/ venv2/awx/ cd venv2/ sed -e 's%/venv/awx/%/venv2/awx/%' -i $(grep -rl 'venv/awx' *) sed -e 's%/var/lib/awx/ipython/%/var/lib/awx/venv2/awx/%' -i $(grep -rl 'awx/ipython' *) find . -name "*.pyc" -delete find . -name "__pycache__" -delete

Utilisation

export PYTHONPATH=/var/lib/awx/venv2/awx/lib/python3.9/site-packages SHELL_PLUS=ipython # awx-manage shell_plus --ipython awx-manage shell_plus

Erreur AttributeError: module 'typing' has no attribute '_ClassVar'

$ ipython
Traceback (most recent call last):
File "/var/lib/awx/ipython/bin/ipython", line 5, in <module>
from IPython import start_ipython
File "/var/lib/awx/ipython/lib/python3.9/site-packages/IPython/__init__.py", line 54, in <module>
from .terminal.embed import embed
File "/var/lib/awx/ipython/lib/python3.9/site-packages/IPython/terminal/embed.py", line 14, in <module>
from IPython.core.magic import Magics, magics_class, line_magic
File "/var/lib/awx/ipython/lib/python3.9/site-packages/IPython/core/magic.py", line 20, in <module>
from . import oinspect
File "/var/lib/awx/ipython/lib/python3.9/site-packages/IPython/core/oinspect.py", line 64, in <module>
class OInfo:
File "/var/lib/awx/venv/awx/lib/python3.9/site-packages/dataclasses.py", line 958, in dataclass
return wrap(_cls)
File "/var/lib/awx/venv/awx/lib/python3.9/site-packages/dataclasses.py", line 950, in wrap
return _process_class(cls, init, repr, eq, order, unsafe_hash, frozen)
File "/var/lib/awx/venv/awx/lib/python3.9/site-packages/dataclasses.py", line 800, in _process_class
cls_fields = [_get_field(cls, name, type)
File "/var/lib/awx/venv/awx/lib/python3.9/site-packages/dataclasses.py", line 800, in <listcomp>
cls_fields = [_get_field(cls, name, type)
File "/var/lib/awx/venv/awx/lib/python3.9/site-packages/dataclasses.py", line 659, in _get_field
if (_is_classvar(a_type, typing)
File "/var/lib/awx/venv/awx/lib/python3.9/site-packages/dataclasses.py", line 550, in _is_classvar
return type(a_type) is typing._ClassVar
AttributeError: module 'typing' has no attribute '_ClassVar'

Solution

mv ./lib/python3.9/site-packages/dataclasses-0.6.dist-info ./lib/python3.9/site-packages/dataclasses-0.6.dist-info.bak mv ./lib/python3.9/site-packages/dataclasses.py ./lib/python3.9/site-packages/dataclasses.py.bak

Gestion d'un job

sudo -u awx -i awx-manage shell_plus --ipython

Analyse d'un job

Analyse d'un job KO

Exemple de changement d'état

su - awx echo "UnifiedJob.objects.filter(status='running').update(status='canceled')" | awx-manage shell_plus

Exemple

#from awx.main.models import UnifiedJob for i in UnifiedJob.objects.filter(): print(i) job_jb = UnifiedJob.objects.filter(id=241021) job_jb.values_list()[0] job_jb.update(status='canceled') start = time.time() UnifiedJob.objects.filter(id=1096679).update(status='canceled') end = time.time() print(end - start)

Effacement d'inventaire

awx-manage shell_plus
Inventory.object.filter(pending_deletion=True).update(pending_deletion=False) Inventory.object.filter(id=inventoryId).delete()

Note : Avant faire une sauvegarde avec ./setup.sh -b

Autres

[awx@aap-crtl-001]$ awx-manage profile_sql --threshold 1 --minutes 5
SQL profiling initiated with a threshold of 1.0 second(s) and a duration of 5.0 minute(s), any queries that meet criteria can be found in /var/log/tower/profile/.