Un environnement Ansible pré-configuré a été mis à votre disposition. Lorsque vous tentez d'exécuter une commande Ansible simple, des avertissements concernant l'interpréteur Python apparaissent. Votre objectif est de faire disparaître ces avertissements et de vous assurer que les commandes Ansible s'exécutent sans aucun problème lié à l'interpréteur.
Pour reproduire les avertissements, exécutez la commande suivante dans votre terminal :
ansible all -m ping
Vous devriez voir une sortie similaire à celle-ci :
[DEPRECATION WARNING]: Distribution ubuntu 22.04 on host localhost should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See
https://docs.ansible.com/ansible/2.10/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
localhost | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
[DEPRECATION WARNING]: Distribution ubuntu 22.04 on host web1 should use /usr/bin/python3, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See
https://docs.ansible.com/ansible/2.10/reference_appendices/interpreter_discovery.html for more information. This feature will be removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
web1 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"ping": "pong"
}
Votre but est d'éliminer ces messages d'obsolescence et de garantir qu'Ansible utilise Python 3.
Tâches
- Identifier les avertissements de l'interpréteur Python lors de l'exécution de la commande Ansible.
- Créer un fichier de configuration Ansible pour spécifier l'interpréteur Python correct.
- Vérifier que les avertissements ont disparu en exécutant à nouveau la commande.
Exigences
- Toutes les opérations doivent être effectuées dans le répertoire
/home/labex/project.
- Créez un fichier de configuration Ansible nommé
ansible.cfg dans le répertoire /home/labex/project.
- Utilisez l'option de configuration appropriée pour définir l'interpréteur Python sur
/usr/bin/python3.
- Le fichier d'inventaire est déjà configuré à l'emplacement
/etc/ansible/hosts (fourni lors de l'initialisation).
Exemple
Une fois Ansible correctement configuré, l'exécution de la commande ne doit plus générer d'avertissements concernant l'interpréteur Python. Le résultat devrait ressembler à ceci :
localhost | SUCCESS => {
"changed": false,
"ping": "pong"
}
web1 | SUCCESS => {
"changed": false,
"ping": "pong"
}