Configurar o Ansible para Usar o Interpretador Python Correto
Você recebeu um ambiente Ansible pré-configurado. Ao tentar executar um comando simples do Ansible, você se depara com avisos sobre o interpretador Python. Sua missão é eliminar esses avisos e garantir que os comandos do Ansible sejam executados sem problemas relacionados ao interpretador.
Para reproduzir os avisos, execute o seguinte comando no seu terminal:
ansible all -m ping
Você deverá ver uma saída semelhante 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"
}
Seu objetivo é eliminar esses avisos e garantir que o Ansible utilize o Python 3.
Tarefas
- Identificar os avisos do interpretador Python ao executar o comando Ansible.
- Criar um arquivo de configuração do Ansible para especificar o interpretador Python correto.
- Verificar se os avisos foram resolvidos executando o comando novamente.
Requisitos
- Todas as operações devem ser realizadas no diretório
/home/labex/project.
- Crie um arquivo de configuração do Ansible chamado
ansible.cfg no diretório /home/labex/project.
- Use a opção de configuração apropriada para definir o interpretador Python como
/usr/bin/python3.
- O arquivo de inventário já está configurado em
/etc/ansible/hosts (fornecido na configuração inicial).
Exemplo
Após configurar o Ansible corretamente, a execução do comando não deve gerar nenhum aviso sobre o interpretador Python. A saída deve ser semelhante a esta:
localhost | SUCCESS => {
"changed": false,
"ping": "pong"
}
web1 | SUCCESS => {
"changed": false,
"ping": "pong"
}