AWXをなんとか動かした

Ansible TowerのOSS版であるAWXを使ってみたくてようやくMacで動かせるとこまでのメモ。 AWXを使えるようになって個人では何が嬉しいかと言われるとGUIでジョブの管理ができるのでいいのではと思った。 個人で使ってメリットを享受できるかはわからないけど使って見たかったのでメモを残す。

詳しい説明はいいのがあったのでこっちを参照。

ansible/ansible-tower at master · h-kojima/ansible · GitHub

動かし方

環境

環境はだいぶ変則的。

  • AWX: 3.0.1
  • AWXの動かし方: docker-compose
  • OS: macOS Mojave 10.14
  • Python: 3.7.2(anaconda3-5.3.1 かつ pyenv使用)
  • Ansible: 2.7.10

4.0.0のバージョンはmacだとうまく動かなかったので新しいのが出たら多分解決するかも。

前提条件

INSTALL.mdに書いてある通りに必要なものをインストールする。

awx/INSTALL.md at devel · ansible/awx · GitHub

Dockerのインストールは、省略。検索すればなんとかなると思う。 あと、必要なpipモジュールのdocker-composeをインストールする。

pip install docker-compose

AWXのインストールと実行

AWXをクローンして、現在(2019/5/17時点)うまく動くと思われる3.0.1に切り替える。最新の安定板4.0.0にしないのは、PCが強制終了で落ちた後docker-compose up -dで実行しても再起動できなくなったから。

git clone https://github.com/ansible/awx 
cd awx
git checkout -b 3.0.1

次にdocker-composeが使えるように、awx/installer/inventoryの修正をする。

# Common Docker parameters
awx_task_hostname=awx
awx_web_hostname=awxweb
# postgres_data_dir=/tmp/pgdocker
postgres_data_dir=/Users/pogin/.local/share/pgdocker
host_port=80
# Docker Compose Install
# use_docker_compose=false
use_docker_compose=true
# The docker_compose.yml file will be created in this directory
# The name of the directory (here "awx") will be the prefix of the docker containers
docker_compose_dir=/Users/pogin/.local/share/awxcompose

変更しないといけないのはdocker_compose_dirパーミッションの関係でエラーが起こる。 postgres_data_diruse_docker_caomposeを変更する理由としては、それぞれ以下の理由。

  • postgres_data_dirは、/tmp/pgdockerにするとVer.4.0.0の時にAWXが動かなくなることが多発して面倒なのでとりあえず変更しとく。
  • use_docker_composeは、docker_compose_dirに設定したディレクトリで、次回からdocker-compose startができるようになるのでtrueに変更しておく。

次はinstall.ymlを実行してAWXのインストールと実行をする。

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

実行後、以下の箇所まで行けば多分成功。

PLAY RECAP ********************************************************************************************
localhost                  : ok=7    changed=3    unreachable=0    failed=0

確認のため、docker psでを実行はするとこんな風に

CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS                                                 NAMES
f3c91abd95b8        ansible/awx_task:3.0.1       "/tini -- /bin/sh -c…"   About an hour ago   Up About an hour    8052/tcp                                              awxcompose_task_1
1e67b9993273        ansible/awx_web:3.0.1        "/tini -- /bin/sh -c…"   About an hour ago   Up About an hour    0.0.0.0:80->8052/tcp                                  awxcompose_web_1
77c62f06ccb4        ansible/awx_rabbitmq:3.7.4   "docker-entrypoint.s…"   About an hour ago   Up About an hour    4369/tcp, 5671-5672/tcp, 15671-15672/tcp, 25672/tcp   awxcompose_rabbitmq_1
085ac0612d3a        postgres:9.6                 "docker-entrypoint.s…"   About an hour ago   Up About an hour    5432/tcp                                              awxcompose_postgres_1
69d3b1aeb2b2        memcached:alpine             "docker-entrypoint.s…"   About an hour ago   Up About an hour    11211/tcp                                             awxcompose_memcached_1

あとはhttp://localhostに1〜2分ぐらい置いてアクセスするとAWXのログイン画面が出てくる

ユーザー名はadmin, passwordで設定されている。

f:id:pogin:20190519204853p:plain
AWXログインページ

いろいろな対処方法

ログを残し忘れたのと再起動で全部ログが消えたので対処したことを思い出してとりあえず書く。

再起動の仕方

Ver.4.0.0なら、デフォルトで定義されてる/tmp/awxcompose/docker-compose.ymldocker-compose up -dで再起動すればいい。 Ver.3.0.1なら、awx/installer/inventoryuse_docker_composeをtrueに設定してdocker-compose up -dで再起動する。

エラーメッセージ毎に対処したもののメモ。

A server error has occured

devel ブランチで起動した時に出たエラー。出たときはすごく困った...。

ログを調べるために以下のようなコマンドを実行してた。

docker logs awx_web -t | less 
docker logs awx_task -t | less 

ログが残っていないのであれだが、the database system is in recovery mode とか awx.conf.settings Database settings are not available, using defaults, error: で検索していた。

原因の一つは、別のPostgrSQLコンテナを動かしていてAWX用のPostgrSQLコンテナに接続できないということでエラーを出していたときがあった。なので既存のコンテナを止めて対処した。ログについてはあとで追記したいが多分しなさそう...。

ansible-playbook -i inventory install.ymlしてもエラーでコンテナが起動しない

ログが残っていないが、これについては昔にAWXを実行して作られた/tmp/pgdockerが原因でうまく動作しないことがあった。これは/tmp/pgdockerを削除することで直った。

There was an issue creating /var/lib/awxcompose as requested: [Errno 13] Permission denied: b'/var/lib/awxcompose'

AWXの3.0.1ではデフォルトで/var/lib/awxcomposeにdocker-compose.ymlファイルを配置する。

github.com

ls -la / | grep private                                  19:45:06
lrwxr-xr-x@   1 root  wheel    11 10 14  2018 etc -> private/etc
drwxr-xr-x    6 root  wheel   192 10 14  2018 private
lrwxr-xr-x@   1 root  wheel    11 10 14  2018 tmp -> private/tmp
lrwxr-xr-x@   1 root  wheel    11 10 14  2018 var -> private/var

$ ls -la /private/ | grep var                              19:44:16
drwxr-xr-x   26 root  wheel   832 10 14  2018 var

ls -la /private/var | grep lib                           19:45:00
drwxr-xr-x    3 root          wheel            96  5 19 15:50 lib

sudoでやればできそうだけど後々面倒そうなので、これはinventorydocker_compose_dirをユーザーフォルダ配下の配下に設定を変更して対処した。

# The docker_compose.yml file will be created in this directory
# The name of the directory (here "awx") will be the prefix of the docker containers
docker_compose_dir=/Users/pogin/.local/share/awxcompose

$HOME/.local/share$XDG_DATA_HOMEで設定される箇所。

wiki.archlinux.jp

error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "process_linux.go:424: container init caused \"rootfs_linux.go:58: mounting \\"/tmp/awxcompose/SECRET_KEY\\" to rootfs

なんかmacが強制終了で落ちたあとAWXを再起動したら、こんな感じのエラーが出てきた。

cd /tmp/docker-compose
ansible-playbook -i inventory install.yml -vvv
Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "process_linux.go:424: container init caused \"rootfs_linux.go:58: mounting \\\"/tmp/awxcompose/SECRET_KEY\\\" to rootfs \\\"/var/lib/docker/overlay2/ba75a051fdae455c34a77e607dbb1c52ad5f03a8eb3f46cf02577ff4e89da0aa/merged\\\" at \\\"/var/lib/docker/overlay2/ba75a051fdae455c34a77e607dbb1c52ad5f03a8eb3f46cf02577ff4e89da0aa/merged/etc/tower/SECRET_KEY\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type Error response from daemon: OCI runtime create failed: container_linux.go:344: starting container process caused "process_linux.go:424: container init caused \"rootfs_linux.go:58: mounting \\\"/tmp/awxcompose/SECRET_KEY\\\" to rootfs \\\"/var/lib/docker/overlay2/9d6a0c7a4909b70ff47f4c75abd44b968277267af21409761ed7c24fc25d6264/merged\\\" at \\\"/var/lib/docker/overlay2/9d6a0c7a4909b70ff47f4c75abd44b968277267af21409761ed7c24fc25d6264/merged/etc/tower/SECRET_KEY\\\" caused \\\"not a directory\\\"\"": unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

AWX does not start after reboot using Docker · Issue #3551 · ansible/awx

何かの拍子にSECRET_KEYがディレクトリになったのが原因っぽい?うまく行かなかったので/tmp/awxcomposeを削除して、もう一度ansible-playbook -i inventory install.ymlをしたらうまくいったはず。

それでもうまく行かないときは/tmp/awxcomposedocker-compose downを実行して全部削除するとうまく行く場合があった。 あと/tmp/pgdockerが古いことが原因でうまくいかないこともあったので/tmp/pgdockerを削除か移動させるとうまくいく。

終わりに

雑になってしまってしまったが、人柱のログを残したいので公開する。 検索しても日本語の情報はうまくいった人の情報しか引っかからないので辛い気持ちになるが諦める。

現在開いてるファイルのディレクトリをロードパスに追加する

特定の開いてるファイルのディレクトリをロードパスに追加する場合は以下のようにやる。

  1. M+: *1キーバインドを押す
  2. ミニバッファにから以下の式を実行する
(add-to-list 'load-path default-directory)

f.elを使う場合はこんな感じ。

(add-to-list 'load-path (f-parent (f-this-file)))

こんなことしようかと思った理由は、なんだかバグってる拡張の調査をしようと思ったから。 emacs -Qで開いて特定の拡張だけ読み込むようにするため、ロードパスに追加したかった。

もっといい方法があるかな?

*1:eval-expression: ミニバッファからLisp式を読み込み,それを評価し,ミニバッファに結果を表示する

LaravelのHomesteadが使えなかった

LaravelのHomesteadというboxを追加しようとしたところなぜか404エラーになった。

⋊> ~/.v/boxes vagrant box add laravel/homestead
The box 'laravel/homestead' could not be found or
could not be accessed in the remote catalog. If this is a private
box on HashiCorp's Atlas, please verify you're logged in via
`vagrant login`. Also, please double-check the name. The expanded
URL and error message are shown below:

URL: ["https://atlas.hashicorp.com/laravel/homestead"]
Error: The requested URL returned error: 404 Not Found

検索して下のリンクに行き着いて中身を読んだけれど、どうも自分の場合と事例が違った。

The box 'laravel/homestead' could not be found or could not be accessed in the remote catalog. If this is a private box on HashiCorp's Atlas · Issue #819 · laravel/homestead · GitHub There was a problem while downloading the metadata for your box · Issue #807 · laravel/homestead · GitHub

そういえばVagrantのバージョンはどうなっているか確認してみる。

⋊> ~/ vagrant --version
Vagrant 1.9.5

Vagrantの本家サイトは2.0.3になっていたのでアップグレードしてみるとエラーが解消された。

⋊> ~/ vagrant box add laravel/homestead
==> box: Loading metadata for box 'laravel/homestead'
    box: URL: https://vagrantcloud.com/laravel/homestead
This box can work with multiple providers! The providers that it
can work with are listed below. Please review the list and choose
the provider you will be working with.

1) hyperv
2) parallels
3) virtualbox
4) vmware_desktop

Enter your choice:

Please Upgrade的なことをエラー文に書かれてるともっとすぐに解消できてたのだけどしょうがない。

kublerの404 Not Found エラーを回避する(Mac)

解決方法

Macだとsedの互換性の問題でrオプションが使えないのでまずgnu-sedを入れる。

$ brew install gnu-sed

lib/cmd/update.shの、rオプションを使っている部分をgsedに書き換える。

$ cd kubler
$ nano lib/cmd/update.sh

-                        sed -r -i s/^STAGE3_DATE=\(\"\|\'\)?[0-9]*\(\"\|\'\)?/STAGE3_DATE=\'"${s3date_remote}"\'/g \
+                        gsed -r -i s/^STAGE3_DATE=\(\"\|\'\)?[0-9]*\(\"\|\'\)?/STAGE3_DATE=\'"${s3date_remote}"\'/g \

kublerの使用するGentoo stage3イメージ?をアップデートする。

./kubler.sh update

cleanしてビルドする。

./kubler.sh clean
./kubler.sh build -c kubler/glibc

経緯

kubler(旧:gentoo-bb)というものを使うとdockerのコンテナサイズを小さく作れるというのを聞いて試して見るとERROR 404: Not Found が出て進まなくなった。

> $ ./kubler.sh build kubler/glibc
*** generate build order
--> required engines:    docker
--> required stage3:     stage3-amd64-hardened+nomultilib stage3-amd64-musl-hardened
--> required builders:   kubler/bob kubler/bob-musl
--> build sequence:      kubler/busybox kubler/glibc
*** gogo!
--2017-05-14 01:12:00--  http://distfiles.gentoo.org/releases/amd64/autobuilds/current-stage3-amd64-hardened+nomultilib/stage3-amd64-hardened+nomultilib-20170420.tar.bz2
Resolving distfiles.gentoo.org... 64.50.236.52, 140.211.166.134, 137.226.34.46, ...
Connecting to distfiles.gentoo.org|64.50.236.52|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-05-14 01:12:01 ERROR 404: Not Found.

*** Got a 404 for stage3-amd64-hardened+nomultilib-20170420.tar.bz2, try running the update command to resolve this.
fatal: Aborted download of /Users/pogin/workspace/kubler/tmp/downloads/stage3-amd64-hardened+nomultilib-20170420.tar.bz2

set -xをkubler.shに入れて調べたけど結局よくわからなかった。

なので、公式のREADME.mdを見直してみると

$ kubler.sh update

というものがあったので、これを実行するとtagをアップデートしてくるっぽいので実行してみる。

$ ./kubler.sh update
*** sync portage container
Warning, skipped sync. Couldn't find a builder image to work with, tried "kubler/bob"
*** check for stage3 updates
dummy/
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
--> bob/                 updated 20170420 -> 20170504 - stage3-amd64-hardened+nomultilib
kubler/
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
--> bob-musl/            updated 20170404 -> 20170509 - stage3-amd64-musl-hardened
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
--> bob-uclibc/          updated 20170405 -> 20170430 - stage3-amd64-uclibc-hardened
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
--> bob/                 updated 20170420 -> 20170504 - stage3-amd64-hardened+nomultilib

Found updates for 1 stage3 file(s), to rebuild run:

    kubler.sh clean
    kubler.sh build -c some_namespace

このままkubler.sh clean; kubler.sh build kubler/glibcとしても同じように404 Not Foundが出て全然アップデートしてくれない...。

どうもMacsedではrオプションを受け付けない様子。

sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]

以下のissueを見てみるとgnu-sedを入れて書き換えれば動くというらしいので入れてみる。
OS X Yosemite “sed: illegal option -- r” fatal error · Issue #1526 · fabric/fabric

$ brew install gnu-sed

該当しそうな箇所をagで探す。

$ ag sed
lib/cmd/update.sh
24:                        sed -r -i s/^STAGE3_DATE=\(\"\|\'\)?[0-9]*\(\"\|\'\)?/STAGE3_DATE=\'"${s3date_remote}"\'/g \

何かしらのエディタで修正する。

$ nano lib/cmd/update.sh
-                        sed -r -i s/^STAGE3_DATE=\(\"\|\'\)?[0-9]*\(\"\|\'\)?/STAGE3_DATE=\'"${s3date_remote}"\'/g \
+                        gsed -r -i s/^STAGE3_DATE=\(\"\|\'\)?[0-9]*\(\"\|\'\)?/STAGE3_DATE=\'"${s3date_remote}"\'/g \

もう一度updateコマンドを実行してみる。

$ ./kubler.sh update
*** sync portage container
Warning, skipped sync. Couldn't find a builder image to work with, tried "kubler/bob"
*** check for stage3 updates
dummy/
--> bob/                 updated 20170420 -> 20170504 - stage3-amd64-hardened+nomultilib
kubler/
--> bob-musl/            updated 20170404 -> 20170509 - stage3-amd64-musl-hardened
--> bob-uclibc/          updated 20170405 -> 20170430 - stage3-amd64-uclibc-hardened
--> bob/                 updated 20170420 -> 20170504 - stage3-amd64-hardened+nomultilib

Found updates for 1 stage3 file(s), to rebuild run:

    ./kubler.sh clean
    ./kubler.sh build -c some_namespace

指示に従ってclean,buildを実行してみる。

$ ./kubler.sh clean
--> remove build artifacts
rootfs.tar files
generated Dockerfiles
PACKAGES.md files
find: -delete: forbidden when symlinks are followed

find: -delete: forbidden when symlinks are followed
なんか不穏なメッセージが出てるがとりあえず次に進む。

$ ./kubler.sh build kubler/glibc
*** generate build order
--> required engines:    docker
--> required stage3:     stage3-amd64-hardened+nomultilib stage3-amd64-musl-hardened
--> required builders:   kubler/bob kubler/bob-musl
--> build sequence:      kubler/busybox kubler/glibc
*** gogo!
--> build image kubler/bob-core
--> phase 2: build kubler/bob-core:20170423
Sending build context to Docker daemon 40.45 kB
Step 1/10 : FROM kubler-gentoo/stage3-amd64-hardened-nomultilib
 ---> e0a88dbeb066
Step 2/10 : LABEL maintainer Erik Dannenberg <erik.dannenberg@xtrade-gmbh.de>
 ---> Using cache
 ---> 3df1f3912ff9
.....

やっとこさ動きました。

終わりに

久々のブログだったので大変だった。
できればPull Requestとかまで行きたいけどどこを書き直そうか。

新しいMagitにしたら動かなくなった

こんなエラーが出た。

Error (magit): git-commit-mode has to be removed

Magit is no longer compatible with the library `git-commit-mode',
which was used in earlier releases.  Please remove it, so that
Magit can use the successor `git-commit' without the obsolete
library getting in the way.  Then restart Emacs.

Error (magit): git-rebase-mode has to be removed

Magit is no longer compatible with the library `git-rebase-mode',
which was used in earlier releases.  Please remove it, so that
Magit can use the successor `git-rebase' without the obsolete
library getting in the way.  Then restart Emacs.

git-commit-mode, git-rebase-modeは最近のMagitだと互換性がないから削除してくださいとのこと。

magitに関連するパッケージが古いことが原因らしい。

対処法としては、

  1. M-x list-package をする
  2. magitに関連しそうなパッケージをキーボードの"d"で選択する。
    この場合git-commit-mode、git-rebase-modeを削除する。
  3. キーボードの"x"で削除を実行してパッケージを削除する。
  4. 削除したらまたmagitをインストールする。
  5. Emacsを再起動する。

これでmagitが動くようになるはず。

新しくなったmagitはこちら。

なんかインデントがなくなって違和感がある…。

ちなみに昔のMagitはこちら。

Stashes: が下に来たから見やすくなった。Stashes:はそんな重要な情報じゃないし確かに上になくて良いと思う。Local:が消えて Remote: の情報が少なくなったのはたまに困ることがありそう。

更新履歴

2015/12/29
1. git-commit-mode、git-rebase-modeを削除するように文章を変更。
2. Emacsを再起動する文言を追加

error "GHCi lacks `:complete' support"

haskell-modeでinteractive-modeの補完を使おうとしたら、こんなメッセージが出た。

[Haskell]error "GHCi lacks `:complete' support"

どういうことかというと、GHC 7.6.3じゃ:completeはサポートしていないという話。

Haskell 7.8に上げろとのこと。

Completion error on OS X: GHCi lacks :complete support · Issue #281 · haskell/haskell-mode · GitHub

第6回init.el読書会に参加しました

自分も書いてみようと思ったので書いてみます。自分はあまり指摘ができないので、

  • 気づいたこと
  • 自分が知らなかった技術

などを書こうと思います。

今回はGithubで検索して見つけたdragonwasrobotさんのinit.elを見ました。
dragonwasrobot/dot-emacs

jade.el


dot-emacs-d/modes/jade.el

これはJadeという、Haml, Slim, などと同様のHTMLテンプレートエンジンです。これは閉じタグがないタイプの軽量マークアップ言語のようです。
例はこんな感じ。
HTML

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>最高にクールなホームページ</title>
        <link rel="stylesheet" href="./css/app.css">
    </head>
    <body>
        <h1>最高にクールなホームページ</h1>
        <p>最高にクールなホームページへようこそ。</p>
        <script src="./js/app.js" charset="UTF-8"></script>
    </body>
</html>

JADE

doctype html
html
  head
    meta(charset='UTF-8')
    title 最高にクールなホームページ
    link(rel='stylesheet', href='./css/app.css')
  body
    h1 最高にクールなホームページ
    p 最高にクールなホームページへようこそ。
    script(src='./js/app.js', charset='UTF-8')

だいぶ楽に書けそうなテンプレートエンジンだと思います。

詳しい説明はこちらへ。
https://gist.github.com/japboy/5402844

dot-emacs.el

dot-emacs.el

気づいたこと、知らなかった設定
L67

(set-fringe-mode 4)

これはフリンジと呼ばれる左右にある余白の設定です。(set-fringe-mode 100)とかするとどんなものなのかがわかりやすい。

L68
iswitch-mode は古い。icomplete-modeかido-modeを使うべきらしい

L75
standard-indent は謎。一体なんの設定なのか。

L108

(setq cursor-type 'bar)

cursor-typeという設定がある。Emacsのカーソルを設定することができる。

(add-to-list 'default-frame-alist '(cursor-type . 'box)) ;; ボックス型カーソル
(add-to-list 'default-frame-alist '(cursor-type . 'hbar)) ;; 下線
(add-to-list 'default-frame-alist '(cursor-type . '(bar . 3)) ;; 幅3ポイントの縦棒カーソル

http://th.nao.ac.jp/MEMBER/zenitani/elisp-j.html#cursor

L110
saveplaceが便利そう。saveplaceはファイルを編集して、終了したときのカーソルの位置を覚えておく機能。


increment-number-at-pointというのがあるのを知った
Vimみたいにカーソル下の数字をインクリメントする機能。
dot-emacs.el#L222
IncrementNumber -EmacsWiki-

L199
kill-all-bufferはたまに便利そう。

;; すべてのバッファを削除する
(defun kill-all-buffers ()
  "Kills all emacs buffers."
  (interactive)
  (mapc (lambda (b) (kill-buffer b)) (buffer-list)))

dot-emacs.el#L199

aliases.el

dot-emacs-d/aliases.el
このファイルはEmacsでシェルのようにaliasを作っている

(defalias 'ms 'magit-status)
(defalias 'qrr 'query-replace-regexp)
(defalias 'er 'eval-region)

よく使うコマンドはこんな風に設定するといいみたいです。

coq.el

Coqについては↓へ。
Coqによる証明プログラミング

dot-emacs-d/modes/coq.el
eval-after-loadで(print)していてeval-after-loadが起きたことがわかりやすい

(eval-after-load "coq-mode"
  '(progn
     (print "In eval-after-load coq"))
     ...)

pretty-mode.elというものがある。
https://github.com/akatov/pretty-mode

終わりに

もう気力が続かないのでここで終わります。

init.el読書会は毎週土曜日22:00時、lingrEmacs部屋でやってるので、興味のある方はぜひ参加してみてください。

http://emacs-jp.github.io/reading-init.el/