kakkotetsu

Ansible AWX の upgrade が楽になっていた (v14.1.0 -> v16.0.0)

小ネタです
Ansible AWX の upgrade というと、かつては「新バージョンで作り直してデータを export import で migrate すれば(一部のデータを除いて)出来るっぽい」「それは商用版であるところの Tower を買えば出来る」といった状況で正直面倒でした
が、いつのまにか大変楽に「新しいコンテナイメージをとってくるだけ」に近い手順で upgrade できるようになっていました

事前情報

参考ドキュメント

環境情報

$ cat /etc/os-release
NAME="Ubuntu"
VERSION="20.04.1 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.1 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal


$ docker --version
Docker version 20.10.2, build 2291f61


$ docker-compose --version
docker-compose version 1.26.2, build unknown

upgrade (v14.1.0 -> v16.0.0)

upgrade 前は v14.1.0 の環境です

  • v14.1.0 新規 install には docker-compose 利用
  • PostgreDB は外部(ホスト的には AWX と同居)のものを利用
    • デフォルトは AWX がコンテナを用意する
 ______________ 
<  AWX 14.1.0  >
 -------------- 
        \   ^__^
         \  (oo)\_______
            (__)      A )\/\
                ||----w |
                ||     ||

Ansible 2.9.11
Copyright © 2019 Red Hat, Inc.
Visit Ansible.com for more information.

事前バックアップ

AWX / PostgreDB が乗っている仮想マシンのスナップショットをとっただけ
本来的には PostgreDB のバックアップなど丁寧にやると良いのでしょうが

upgrade

最新バージョンのリポジトリを clone してきて

$ mkdir ~/work/awx_16.0.0
$ cd ~/work/awx_16.0.0/

$ git clone https://github.com/ansible/awx.git -b 16.0.0
Cloning into 'awx'...
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 262009 (delta 6), reused 1 (delta 0), pack-reused 261994
Receiving objects: 100% (262009/262009), 233.40 MiB | 13.33 MiB/s, done.
Resolving deltas: 100% (202532/202532), done.
Note: switching to '9bf721665d9ec3a29aa24f209c1b6cfc5554daea'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false


$ cd awx/
$ git show
commit 9bf721665d9ec3a29aa24f209c1b6cfc5554daea (HEAD, tag: 16.0.0)
Merge: 871b86273 5f6a383eb
Author: softwarefactory-project-zuul[bot] <33884098+softwarefactory-project-zuul[bot]@users.noreply.github.com>
Date:   Thu Dec 10 17:39:28 2020 +0000

    Merge pull request #8723 from ryanpetrello/bump-16

    Bump version to 16.0.0

    Reviewed-by: https://github.com/apps/softwarefactory-project-zuul

各種インストールパラメータが書いてある inventory ファイルだけは新規インストールに使ったものを流用しています
(公式では password 系だけを新規 vars.yml に用意する手順)
以下の ~/work/awx/installer/inventory が前のバージョンを新規インストールした時に作った設定ファイルです

$ cd installer/
$ cp ~/work/awx/installer/inventory .
$ git diff
diff --git a/installer/inventory b/installer/inventory
index 89d0684a7..7d0e9dfa8 100644
--- a/installer/inventory
+++ b/installer/inventory
@@ -62,13 +62,13 @@ dockerhub_base=ansible
 # Common Docker parameters
 awx_task_hostname=awx
 awx_web_hostname=awxweb
-postgres_data_dir="~/.awx/pgdocker"
+#postgres_data_dir="~/.awx/pgdocker"
 host_port=80
 host_port_ssl=443
 #ssl_certificate=
 # Optional key file
 #ssl_certificate_key=
-docker_compose_dir="~/.awx/awxcompose"
+docker_compose_dir="/opt/awx/awxcompose"

 # Required for Openshift when building the image on your own
 # Optional for Openshift if using Dockerhub or another prebuilt registry
@@ -82,21 +82,15 @@ docker_compose_dir="~/.awx/awxcompose"

 # Set pg_hostname if you have an external postgres server, otherwise
 # a new postgres service will be created
-# pg_hostname=postgresql
+pg_hostname=10.3.12.53
 pg_username=awx
 # pg_password should be random 10 character alphanumeric string, when postgresql is running on kubernetes
 # NB: it's a limitation of the "official" postgres helm chart
-pg_password=awxpass
+pg_password=password
 pg_database=awx
 pg_port=5432
 #pg_sslmode=require

-# If requiring SSL communication (e.g. pg_sslmode='verify-full') with Postgres
-# and using a self-signed certificate or a certificate signed by a custom CA
-# set pg_root_ca_file to a file containing the self-signed certificate or the
-# root CA certificate chain.
-# pg_root_ca_file='example_root_ca.crt'
-
 # The following variable is only required when using the provided
 # containerized postgres deployment on OpenShift
 # pg_admin_password=postgrespass
@@ -115,7 +109,7 @@ pg_port=5432
 # This will create or update a default admin (superuser) account in AWX, if not provided
 # then these default values are used
 admin_user=admin
-admin_password=password
+admin_password=admin

 # Whether or not to create preload data for demonstration purposes
 create_preload_data=True
@@ -136,9 +130,9 @@ secret_key=awxsecret
 # awx_official=false

 # Container networking configuration
 # Set the awx_task and awx_web containers' search domain(s)
@@ -151,7 +145,7 @@ secret_key=awxsecret
 #project_data_dir=/var/lib/awx/projects

 # AWX custom virtual environment folder. Only usable for local install.
-#custom_venv_dir=/opt/my-envs/
+custom_venv_dir=/opt/awx/my-envs/

 # CA Trust directory. If you need to provide custom CA certificates, supplying
 # this variable causes this directory on the host to be bind mounted over
@@ -178,6 +172,6 @@ secret_key=awxsecret
 #

 # Add extra hosts to docker compose file. This might be necessary to
-# sneak in servernames. For example for DMZ self-signed CA certificates.
+# sneak in servernames. For exmaple for DMZ self-signed CA certificates.
 # Equivialent to using the --add-host parameter with "docker run".
 #docker_compose_extra_hosts="otherserver.local:192.168.0.1,ldap-server.local:192.168.0.2"

あとは新規インストールの時と同様に playbook を流すだけ

$ ansible-playbook -i inventory install.yml

...<snip>

TASK [local_docker : Create Docker Compose Configuration] *******************************************************************************************************************************************************************************
ok: [localhost] => (item={'file': 'environment.sh', 'mode': '0600'})
changed: [localhost] => (item={'file': 'credentials.py', 'mode': '0600'})
ok: [localhost] => (item={'file': 'docker-compose.yml', 'mode': '0600'})
changed: [localhost] => (item={'file': 'nginx.conf', 'mode': '0600'})
ok: [localhost] => (item={'file': 'redis.conf', 'mode': '0664'})

TASK [local_docker : Render SECRET_KEY file] ********************************************************************************************************************************************************************************************
ok: [localhost]

TASK [local_docker : Start the containers] **********************************************************************************************************************************************************************************************
changed: [localhost]

TASK [local_docker : Update CA trust in awx_web container] ******************************************************************************************************************************************************************************
changed: [localhost]

TASK [local_docker : Update CA trust in awx_task container] *****************************************************************************************************************************************************************************
changed: [localhost]

TASK [local_docker : Create Preload data] ***********************************************************************************************************************************************************************************************
ok: [localhost]

PLAY RECAP ******************************************************************************************************************************************************************************************************************************
localhost                  : ok=12   changed=4    unreachable=0    failed=0    skipped=95   rescued=0    ignored=0

状態確認

$ docker ps --no-trunc
CONTAINER ID                                                       IMAGE                COMMAND                                                  CREATED       STATUS         PORTS                  NAMES
ccddcc82e0de1d3c0755c6acb5e7b5ffe22a80539d6ef542ba3236494886e66d   ansible/awx:16.0.0   "/usr/bin/tini -- /usr/bin/launch_awx_task.sh"           2 hours ago   Up 3 minutes   8052/tcp               awx_task
9f3370c7b6f956efded176b4ce48710db2dda15e068e3b76325cea27e27c6fc9   ansible/awx:16.0.0   "/usr/bin/tini -- /bin/sh -c /usr/bin/launch_awx.sh"     2 hours ago   Up 3 minutes   0.0.0.0:80->8052/tcp   awx_web
5e375b9f22fb8c83fc507ee1398390258b34b1e5fda24a185bb25a43bcb8f98a   redis                "docker-entrypoint.sh /usr/local/etc/redis/redis.conf"   2 hours ago   Up 3 minutes   6379/tcp               awx_redis
$ cd /opt/awx/awxcompose/

$ docker-compose images
Container   Repository     Tag       Image Id       Size
----------------------------------------------------------
awx_redis   redis         latest   41de2cc0b30e   104.2 MB
awx_task    ansible/awx   16.0.0   125dda56af33   1.535 GB
awx_web     ansible/awx   16.0.0   125dda56af33   1.535 GB


$ docker-compose logs --tail=30

GUI アクセスも良さげ

f:id:kakkotetsu:20210113134623p:plain

認証情報や template などなど一通り前のバージョンで作っていたものが残っていることを確認

余談ですが、今回は install に使う playbook 内の roll なども最新で使いたいのでマルっとリポジトリを pull してきて使いましたが、単にリポジトリ直下の VERSION をあげたいバージョンに書き換えて install.yml を流すだけでも動くといえば動きます

upgrade 後に発生するかも知れない問題

割とバージョン固有な話が多いですが、自分がブチ当たった問題をいくつか紹介しておきます

upgrade 後 GUI で Settings ページにアクセスできなくなっていた

自分はこの問題に遭遇したのですが、upgrade 後に GUI で Settings ページが正しく表示されない問題が起きました

$ docker-compose logs --tail=30

...<snip>

awx_web  | 2021/01/13 02:35:21 [crit] 90#0: *253 open() "/var/lib/nginx/tmp/uwsgi/9/00/0000000009" failed (13: Permission denied) while reading upstream, client: 10.3.12.13, server: _, request: "OPTIONS /api/v2/settings/all/ HTTP/1.1", upstream: "uwsgi://127.0.0.1:8050", host: "10.3.12.53", referrer: "http://10.3.12.53/"

Can't go to Settings page. Nothing happens の issue を見ると、前々からバージョンアップ時に発生することがある問題のようで、以下のように権限設定修正してやれば直りました

$ docker exec -it awx_web bash -c "chown -R nginx:nginx /var/lib/nginx"

upgrade 後 HTTP しか使っていないのに WebSocket 通信が wss でされる (v16.0.0 固有問題)

upgrade 後に WebUI で WebSocket 周りがちゃんと動いていないように見えたのですが、こんな Issue がありました
試していないけど HTTPS 環境では元々 wss で動くので問題が顕在化しないかもです

Websockets defaults to wss when connecting unsecurely

upgrade 後 ジョブ実行時の output が auto refresh されない (v16.0.0 固有問題)

upgrade 後に ジョブ実行した時に完了するまで output が出力されない問題が起きました
以下のような Issue がありました

AWX 16.0.0 UI not auto refreshing job output

upgrade 後 dynamic inventory スクリプトを指定する入力が出来なくなっていた (v16.0.0 固有問題?)

upgrade 後に inventories > Sources で Sourced from a Project を使って Inventory File 欄に Dynamic Inventory のスクリプトを指定しようとしたら、入力できませんでした
探すと以下の Issue がありました

inventory file field should be typable

おしまい

大した手順ではないのですが「大した手順でなくなって良かったね」という話です
何年か前に「AWX?コンテナなら upgrade なんて latest 取ってくるだけっしょ?」と言われて泣いたことがあるのですが、今なら「そんな感じっすね」と言えそうです