Configurar Ansible para usar el intérprete de Python correcto
Se te ha proporcionado un entorno de Ansible preconfigurado. Al intentar ejecutar un comando sencillo de Ansible, aparecen advertencias sobre el intérprete de Python. Tu objetivo es eliminar estas advertencias y asegurar que los comandos de Ansible se ejecuten sin problemas relacionados con el intérprete.
Para reproducir las advertencias, ejecuta el siguiente comando en tu terminal:
ansible all -m ping
Deberías ver una salida similar a esta:
[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"
}
Tu meta es eliminar estas advertencias y asegurar que Ansible utilice Python 3.
Tareas
- Identificar las advertencias del intérprete de Python al ejecutar el comando de Ansible.
- Crear un archivo de configuración de Ansible para especificar el intérprete de Python correcto.
- Verificar que las advertencias se hayan resuelto ejecutando el comando nuevamente.
Requisitos
- Todas las operaciones deben realizarse en el directorio
/home/labex/project.
- Crea un archivo de configuración de Ansible llamado
ansible.cfg en el directorio /home/labex/project.
- Utiliza la opción de configuración adecuada para establecer el intérprete de Python en
/usr/bin/python3.
- El archivo de inventario ya está configurado en
/etc/ansible/hosts (proporcionado en la configuración inicial).
Ejemplo
Después de configurar Ansible correctamente, la ejecución del comando no debería producir ninguna advertencia sobre el intérprete de Python. La salida debería verse similar a esta:
localhost | SUCCESS => {
"changed": false,
"ping": "pong"
}
web1 | SUCCESS => {
"changed": false,
"ping": "pong"
}