본문 바로가기
인프라/앤서블(Ansible)

[ANSIBLE] 앤서블 ansible.legacy.setup": {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3 에러 해결방법

by IT맥구리나스 2024. 10. 17.

개요

- ansible 서버 마이그레이션 후 기존에 잘되던 명령이 일부 호스트에

아래와 같은 에러를 뱉으면서 수행되 않는 문제가 발생했다.

- ansible이 명령을 내리는 host에 설치된 python을 이용하는데 해당 python 모듈이

제대로 동작되지 않으면서 발생된 문제다.

- test-seo라는 서버에는 python3가 설치되어 있음에도 명령에러가 발생하는 상황이다

 

fatal: [test-seo]: FAILED! => {"ansible_facts": {}, "changed": false, "failed_modules": {"ansible.legacy.setup": {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python3"}, "exception": "Traceback (most recent call last):\r\n  File \"/home/infra/.ansible/tmp/ansible-tmp-1729139990.1288748-1725907-28168791460581/AnsiballZ_setup.py\", line 102, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/infra/.ansible/tmp/ansible-tmp-1729139990.1288748-1725907-28168791460581/AnsiballZ_setup.py\", line 94, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/infra/.ansible/tmp/ansible-tmp-1729139990.1288748-1725907-28168791460581/AnsiballZ_setup.py\", line 37, in invoke_module\r\n    from ansible.module_utils import basic\r\n  File \"/tmp/ansible_ansible.legacy.setup_payload_32x84a4b/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/basic.py\", line 176, in <module>\r\nModuleNotFoundError: No module named 'ansible.module_utils.six.moves'\r\n", "failed": true, "module_stderr": "Shared connection to test-seo closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n  File \"/home/infra/.ansible/tmp/ansible-tmp-1729139990.1288748-1725907-28168791460581/AnsiballZ_setup.py\", line 102, in <module>\r\n    _ansiballz_main()\r\n  File \"/home/infra/.ansible/tmp/ansible-tmp-1729139990.1288748-1725907-28168791460581/AnsiballZ_setup.py\", line 94, in _ansiballz_main\r\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n  File \"/home/infra/.ansible/tmp/ansible-tmp-1729139990.1288748-1725907-28168791460581/AnsiballZ_setup.py\", line 37, in invoke_module\r\n    from ansible.module_utils import basic\r\n  File \"/tmp/ansible_ansible.legacy.setup_payload_32x84a4b/ansible_ansible.legacy.setup_payload.zip/ansible/module_utils/basic.py\", line 176, in <module>\r\nModuleNotFoundError: No module named 'ansible.module_utils.six.moves'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}}, "msg": "The following modules failed to execute: ansible.legacy.setup\n"}    

 

test-seo 서버의 python vesrsion

 

 

 

해결방법

- ansible_python_interpreter를 다른 버전으로 지정해야한다.

- 테스트를 여러번해본 결과, 결론적으로 말하면 python3.12버전은 ansible에서 사용하는 모듈호환이 안되는 듯 보인다.

- 서버마다 각각의 환격이 다르기때문에 ansible.cfg에서 설정할 수 없고 플레이븍 yml 파일에 일일이 interpreter_python 설정을 할 수 없으니 host 인벤토리에 지정하는 방법을 선택했다.

 

- 해당서버에는 python3.10버전이 존재했다

 

[123.123.123.123]
test-seo ansible_python_interpreter=/usr/bin/python3.10

 

 

참고로 글로벌하게 전체 host의 인터프리터를 지정하기위해서는 /etc/ansible/ansibe.cfg에서 설정하면 된다.

[default]

interpreter_python = /usr/bin/python3.10

 

 

여담

실수로 전체 aptupgrade를 하는 바람에 anisible까지 업그레이드가 되어 저런 일까지 발생했었다..

 

chatgpt로 물어봤을 때  ansible을 업그레이드해라. pip install를 통해 뭐 설치해라 등 chatgpt가 제시한걸

그대로 따라했다가 ansible 명령이 전체적으로 안되어 서버까지 교체하는 일이 있었다...

 

리눅스는 왠만하면 업그레이드나 추가설치는 보수적으로 접근해야한다는걸 다시한번 느꼈다..

구글로 검색했을때 나와 동일한 사례가 있었긴 했는데.. chatgpt가 없으면 안되는 몸이 되버려서 더 의존을 한 것같다..

 

그렇기에 나와 같은 불상사가 안일어나길 바라면서 이렇게 블로그 글 작성해본다..

반응형

댓글