AWX on AWS(EC2) を構築する


背景

AWXを触ってみたいとAWSに構築しようと思いましたところ、公式の構成はかなり冗長化されてて課金やばそう

ということでEC2にインストールして実行してみます

やること

EC2 を立てて、そこにAWXを導入します

AWS環境

項目 バージョン
AMI Ubuntu Server 18.04 LTS (HVM), SSD Volume Type - ami-08046c40513c3265e (64 ビット x86)
Ubuntu Ubuntu Server 18.04 LTS (HVM)

構築

EC2を立てる

以下の要件に従って作成します。

私はUbuntu Server 18.04 LTS (HVM), SSD Volume Typet2.midiumで立ち上げました

ポートは80, 443, 22を開けてます

System Requirements

The system that runs the AWX service will need to satisfy the following requirements

  • At least 4GB of memory
  • At least 2 cpu cores
  • At least 20GB of space
  • Running Docker, Openshift, or Kubernetes
  • If you choose to use an external PostgreSQL database, please note that the minimum version is 10+.

AWXを導入する

以下のAWX公式リポジトリのマークダウンに方法が書いてありますので、これを基準に進めます

AWSのインストールをする前に以下のパッケージが必要になりますので、準備していきます

Prerequisites

Before you can run a deployment, you'll need the following installed in your local environment:

  • Ansible Requires Version 2.8+
  • Docker
    A recent version
  • docker Python module
    This is incompatible with docker-py. If you have previously installed docker-py, please uninstall it.
    We use this module instead of docker-py because it is what the docker-compose Python module requires.
  • GNU Make
    ― Git Requires Version 1.8.4+
  • Python 3.6+
  • Node 10.x LTS version
    This is only required if you're building your own container images with use_container_for_build=false
  • NPM 6.x LTS
    This is only required if you're building your own container images with use_container_for_build=false

Ansibleのインストール

リポジトリを更新して最新版をインストールします

sudo apt update
sudo apt install software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt install ansible -y

apt標準のリポジトリだとVersionが2.8まで上がらないので以下のようなエラーが表示されるので注意

hoge@hogehoge:~/awx/installer$ ansible-playbook -i inventory install.yml
/usr/lib/python2.7/dist-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release.
  from cryptography.exceptions import InvalidSignature
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.

The error appears to have been in '/home/ubuntu/awx/installer/roles/local_docker/tasks/compose.yml': line 39, column 7, but may   
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

- block:
    - name: Start the containers
      ^ here

Dockerのインストール

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.

sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io -y

GNU Makeのバージョン確認

これはたぶんデフォで入っているはず

$ make --version
GNU Make 4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Gitのバージョン確認

これもデフォで入っとった。

$ git --version
git version 2.17.1

Python3.7 のインストール

$ python3 --version
Python 3.6.9

3.6はすでに入っているようですが、もうすぐEOLになるので3.7にしときます。

この後でawxをgit pullした後にpipenvでバージョン固定します

(いる人は)pipのインストールとDocker pythonモジュールのインストール

sudo apt install python-pip -y
pip install docker

node, npmのインストール

sudo apt install nodejs npm -y
sudo npm install npm --global

AWXをGitリポジトリからpull

git clone https://github.com/ansible/awx.git

pythonのバージョン固定

# 必要なライブラリのインストール
sudo apt-get install git gcc make openssl libssl-dev libbz2-dev libreadline-dev libsqlite3-dev zlib1g-dev -y

# pyenvをGitリポジトリからクローン
git clone https://github.com/pyenv/pyenv.git ~/.pyenv

# バッシュ設定
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc

# 3.7.9インストール
pyenv install 3.7.9

# ローカルは3.7.9に固定
cd awx/
pyenv local 3.7.9

こんな感じ

~/awx$ python --version
Python 3.7.9

これをしないと

TASK [local_docker : Start the containers] ***************************************************************************************fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (Docker SDK for Python: docker (Python >= 2.7) or docker-py (Python 2.6)) on ip-10-2-1-31's Python /usr/bin/python3. Please read module documentation and install in the appropriate location. If the required library is installed, but Ansible is using the wrong Python interpreter, please
consult the documentation on ansible_python_interpreter, for example via `pip install docker` or `pip install docker-py` (Python 2.6). The error was: No module named 'requests'"}

各種設定を実施

インストールする際のパスワードやポートの設定を、inventoryファイルに行います

vi ~/awx/installer/inventory

install用のplaybookを実行

インストーラ実行

cd ~/awx/installer
sudo ansible-playbook -i inventory install.yml

トラブル

この時に以下のような問題で少しと間取りましたので、同じかた見えましたら以下参照ください

pyenvでpython3を標準利用にしてたが、そのせいで動作しない

~/awx/installer/inventoryにはpython3を使うようなコマンドが入っているためこれをpythonにするように変更

pipでdocker-pyとdockerを両方実行してしまった

docker-pyはdockerに含まれるようになったので、一度両方削除してからdockerのみ実行する

まとめ

何とかインストールできました。
いろいろ触ってみたいと思います