[Ansible] AWX 설치하기DevOps/Ansible2022. 4. 21. 17:26
Table of Contents
728x90
✔️ AWX란 ?
Ansible 위에 구축된 웹 기반의 인터페이스이다.
AWX의 목적은 플레이북의 실행과 모니터링이다.
✔️ Docker 설치
Docker를 이용해 AWX를 설치해보자
우선 Docker를 설치하고 Docker-Compose를 설치한 뒤 AWX를 설치할 것이다.
사용할 환경은 CentOS 운영체제이며 Docker가 설치되어 있지 않다면 다음 명령을 이용해 Docker를 설치하자
공식 문서는 위와 같다.
아래 명령어를 순서대로 입력하면 도커 설치가 완료된다.
sudo yum -y yum-utils
sudo yum-config-manager
--add-repo
https://download.docker.com/linux/centos/docker-ce.repo
yum repolist
sudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable --now docker
✔️ Docker-Compose 설치
sudo yum -y yum-utils
sudo yum-config-manager
--add-repo
https://download.docker.com/linux/centos/docker-ce.repo
yum repolist
sudo yum install docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable --now docker
yum install -y python3 python3-pip
sudo yum install -y python3 python3-pip
pip3
sudo -H pip3 install --upgrade --ignore-installed pip setuptools
sudo pip3 install docker-compose
docker-compose --version
✔️ AWX 설치
[vagrant@controller ~]$ cd awx/
[vagrant@controller awx]$ ls
API_STANDARDS.md CHANGELOG.md DCO_1_1.md ISSUES.md MANIFEST.in setup.cfg VERSION
awx config docs LICENSE.md pytest.ini setup.py
awx_collection CONTRIBUTING.md installer Makefile README.md tools
awxkit DATA_MIGRATION.md INSTALL.md manage.py requirements tox.ini
설정 파일을 수정한다.~/aws/installer/invertory
# :se nu 로 라인 넘버를 출력하고 108, 141 line의 주석을 해제한뒤 다음을 설정한다.
108 admin_password=[사용할 비밀번호] # 패스워드 지정
141 project_data_dir=/var/lib/awx/projects # 플레이북을 배치시켜놓는 디렉토리를 지정
실행
[vagrant@controller installer]$ ansible-playbook -i inventory install.yml -b
✔️ 설치 오류 해결
오류 발생 1
libselinux-python이 없다고 나옴
TASK [local_docker : Create Docker Compose Configuration] ************************************************************
failed: [localhost] (item={u'mode': u'0600', u'file': u'environment.sh'}) => {"ansible_loop_var": "item", "changed": false, "checksum": "b05cf3fcc9f1563ce055b36d17c24a9aab7be641", "item": {"file": "environment.sh", "mode": "0600"}, "msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"}
failed: [localhost] (item={u'mode': u'0600', u'file': u'credentials.py'}) => {"ansible_loop_var": "item", "changed": false, "checksum": "b2d9c9f22fac757c4a7d9188d379519b9e5ea1ef", "item": {"file": "credentials.py", "mode": "0600"}, "msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"}
failed: [localhost] (item={u'mode': u'0600', u'file': u'docker-compose.yml'}) => {"ansible_loop_var": "item", "changed": false, "checksum": "5dde5f4ab25bb183bb23c69072d683d4fa7cfd69", "item": {"file": "docker-compose.yml", "mode": "0600"}, "msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"}
failed: [localhost] (item={u'mode': u'0600', u'file': u'nginx.conf'}) => {"ansible_loop_var": "item", "changed": false, "checksum": "7433a2df79a34332d52f4a7b969614d1cec43a9b", "item": {"file": "nginx.conf", "mode": "0600"}, "msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"}
failed: [localhost] (item={u'mode': u'0664', u'file': u'redis.conf'}) => {"ansible_loop_var": "item", "changed": false, "checksum": "4fe3f9421d102ffe15827f7a685fc9c8d5a20b78", "item": {"file": "redis.conf", "mode": "0664"}, "msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!"}
해결
libselinux-python3 설치
[vagrant@controller installer]$ sudo yum -y install libselinux-python3
오류 발생 2
docker-compose 명령어가 없다고 뜸
fatal: [localhost]: FAILED! => {"changed": true, "cmd": "docker-compose run --rm --service-ports task awx-manage migrate --no-input", "delta": "0:00:00.005528", "end": "2022-04-20 05:27:59.288282", "msg": "non-zero return code", "rc": 127, "start": "2022-04-20 05:27:59.282754", "stderr": "/bin/sh: docker-compose: command not found", "stderr_lines": ["/bin/sh: docker-compose: command not found"], "stdout": "", "stdout_lines": []}
현재는 bash이고 Bourne shell을 못찾고 있음
[vagrant@controller installer]$ echo $PATH
/home/vagrant/.vscode-server/bin/dfd34e8260c270da74b5c2d86d61aee4b6d56977/bin/remote-cli:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/vagrant/.local/bin:/home/vagrant/bin
해결
심볼릭 링크를 걸어서 해결
[vagrant@controller installer]$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
local 디렉토리는 PATH 변수에 보통 등록이 안되어 있어 찾지 못한다.
심볼릭 링크를 걸고 docker를 실행해보자
sudo docker ps
4개의 컨테이너가 실행되고 있으며 AWX를 설치한 IP를 통해 AWX 웹 인터페이스에 접속 가능하다면 해결 완료
오류 발생 3
local_docker : Create Preload data 작업에서 오류 발생
TASK [local_docker : Create Preload data] *******************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "cmd": ["docker", "exec", "awx_task", "bash", "-c", "/usr/bin/awx-manage create_preload_data"], "delta": "0:00:05.517434", "end": "2022-04-20 05:51:52.256205", "msg": "non-zero return code", "rc": 1, "start": "2022-04-20 05:51:46.738771", "stderr": "Traceback (most recent call last):\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 217, in ensure_connection\n self.connect()\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 195, in connect\n self.connection = self.get_new_connection(conn_params)\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/postgresql/base.py\", line 178, in get_new_connection\n connection = Database.connect(**conn_params)\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/psycopg2/__init__.py\", line 126, in connect\n conn = _connect(dsn, connection_factory=connection_factory, **kwasync)\npsycopg2.OperationalError: FATAL: the database system is starting up\n\n\nThe above exception was the direct cause of the following exception:\n\nTraceback (most recent call last):\n File \"/usr/bin/awx-manage\", line 8, in <module>\n sys.exit(manage())\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/__init__.py\", line 154, in manage\n execute_from_command_line(sys.argv)\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/core/management/__init__.py\", line 381, in execute_from_command_line\n utility.execute()\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/core/management/__init__.py\", line 375, in execute\n self.fetch_command(subcommand).run_from_argv(self.argv)\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/core/management/base.py\", line 323, in run_from_argv\n self.execute(*args, **cmd_options)\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/core/management/base.py\", line 364, in execute\n output = self.handle(*args, **options)\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/management/commands/create_preload_data.py\", line 17, in handle\n if Organization.objects.count():\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/models/manager.py\", line 82, in manager_method\n return getattr(self.get_queryset(), name)(*args, **kwargs)\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/models/query.py\", line 392, in count\n return self.query.get_count(using=self.db)\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/models/sql/query.py\", line 504, in get_count\n number = obj.get_aggregation(using, ['__count'])['__count']\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/models/sql/query.py\", line 489, in get_aggregation\n result = compiler.execute_sql(SINGLE)\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/models/sql/compiler.py\", line 1140, in execute_sql\n cursor = self.connection.cursor()\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 256, in cursor\n return self._cursor()\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 233, in _cursor\n self.ensure_connection()\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 217, in ensure_connection\n self.connect()\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/utils.py\", line 89, in __exit__\n raise dj_exc_value.with_traceback(traceback) from exc_value\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 217, in ensure_connection\n self.connect()\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 195, in connect\n self.connection = self.get_new_connection(conn_params)\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/postgresql/base.py\", line 178, in get_new_connection\n connection = Database.connect(**conn_params)\n File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/psycopg2/__init__.py\", line 126, in connect\n conn = _connect(dsn, connection_factory=connection_factory, **kwasync)\ndjango.db.utils.OperationalError: FATAL: the database system is starting up", "stderr_lines": ["Traceback (most recent call last):", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 217, in ensure_connection", " self.connect()", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 195, in connect", " self.connection = self.get_new_connection(conn_params)", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/postgresql/base.py\", line 178, in get_new_connection", " connection = Database.connect(**conn_params)", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/psycopg2/__init__.py\", line 126, in connect", " conn = _connect(dsn, connection_factory=connection_factory, **kwasync)", "psycopg2.OperationalError: FATAL: the database system is starting up", "", "", "The above exception was the direct cause of the following exception:", "", "Traceback (most recent call last):", " File \"/usr/bin/awx-manage\", line 8, in <module>", " sys.exit(manage())", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/__init__.py\", line 154, in manage", " execute_from_command_line(sys.argv)", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/core/management/__init__.py\", line 381, in execute_from_command_line", " utility.execute()", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/core/management/__init__.py\", line 375, in execute", " self.fetch_command(subcommand).run_from_argv(self.argv)", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/core/management/base.py\", line 323, in run_from_argv", " self.execute(*args, **cmd_options)", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/core/management/base.py\", line 364, in execute", " output = self.handle(*args, **options)", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/awx/main/management/commands/create_preload_data.py\", line 17, in handle", " if Organization.objects.count():", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/models/manager.py\", line 82, in manager_method", " return getattr(self.get_queryset(), name)(*args, **kwargs)", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/models/query.py\", line 392, in count", " return self.query.get_count(using=self.db)", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/models/sql/query.py\", line 504, in get_count", " number = obj.get_aggregation(using, ['__count'])['__count']", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/models/sql/query.py\", line 489, in get_aggregation", " result = compiler.execute_sql(SINGLE)", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/models/sql/compiler.py\", line 1140, in execute_sql", " cursor = self.connection.cursor()", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 256, in cursor", " return self._cursor()", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 233, in _cursor", " self.ensure_connection()", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 217, in ensure_connection", " self.connect()", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/utils.py\", line 89, in __exit__", " raise dj_exc_value.with_traceback(traceback) from exc_value", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 217, in ensure_connection", " self.connect()", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/base/base.py\", line 195, in connect", " self.connection = self.get_new_connection(conn_params)", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/django/db/backends/postgresql/base.py\", line 178, in get_new_connection", " connection = Database.connect(**conn_params)", " File \"/var/lib/awx/venv/awx/lib/python3.6/site-packages/psycopg2/__init__.py\", line 126, in connect", " conn = _connect(dsn, connection_factory=connection_factory, **kwasync)", "django.db.utils.OperationalError: FATAL: the database system is starting up"], "stdout": "", "stdout_lines": []}
해당 명령을 실행해 오류 해결
[vagrant@controller installer]$ sudo docker exec awx_task bash -c "/usr/bin/awx-manage create_preload_data"
An organization is already in the system, exiting.
(changed: False)
[vagrant@controller installer]$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ef78af739529 ansible/awx:17.1.0 "/usr/bin/tini -- /u…" 6 minutes ago Up 5 minutes 8052/tcp awx_task
56bfc941250c ansible/awx:17.1.0 "/usr/bin/tini -- /b…" 10 minutes ago Up 5 minutes 0.0.0.0:80->8052/tcp, :::80->8052/tcp awx_web
33a32d736f0a postgres:12 "docker-entrypoint.s…" 10 minutes ago Up 5 minutes 5432/tcp awx_postgres
118ab6e1c7ca redis "docker-entrypoint.s…" 10 minutes ago Up 5 minutes 6379/tcp awx_redis
728x90
'DevOps > Ansible' 카테고리의 다른 글
[Ansible] AWX를 이용해 플레이북 런칭 및 예약, 모니터링하기 (0) | 2022.04.21 |
---|---|
[Ansible] vault (플레이북의 암호화) (0) | 2022.04.21 |
[Ansible] ansible-galaxy 사용법 (0) | 2022.04.21 |
[Ansible] 플레이 레벨에서 작업 실행 순서 (0) | 2022.04.21 |
[Ansible] artifact 재사용 - 역할(roles) (0) | 2022.04.21 |
@TTOII :: 뭉게뭉게 클라우드
영차영차 성장 블로그
포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!