見出し画像

Ansible-navigatorをコンテナ上で使ってみる。

Ansible-navigatorが動くコンテナイメージを作るDockerfile

FROM alpine:edge

RUN echo -e "https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories && \
   apk --no-cache add podman tzdata fuse-overlayfs && \
   apk --no-cache add gcc musl-dev libffi-dev oniguruma-dev && \
   apk --no-cache add --repository http://dl-cdn.alpinelinux.org/alpine/v3.11/main/ python3~=3.8 python3-dev && \
   pip3 install --upgrade pip && \
   pip3 install wheel && \
   pip3 install ansible-navigator && \
   echo -e "[storage]\n  driver = \"overlay\"\n  [storage.options]\n    mount_program = \"/usr/bin/fuse-overlayfs\"" > /etc/containers/storage.conf && \
   echo -e "[registries.search]\nregistries = ['docker.io', 'quay.io']" > /etc/containers/registries.conf && \
   adduser --disabled-password podman && \
   echo "podman:100000:65536" >> /etc/subuid && \
   echo "podman:100000:65536" >> /etc/subgid

USER podman
WORKDIR /home/podman
RUN pip3 install ansible-navigator --user && \
   echo 'export PATH=$HOME/.local/bin:$PATH' >> ~/.profile && \
   source ~/.profile

Pingモジュールが動くところまで確認します。

~ $ ansible-navigator run ping.yml -i hosts --mode stdout

PLAY [server] ******************************************************************

TASK [ping] ********************************************************************
ok: [192.168.0.4]

TASK [debug] *******************************************************************
ok: [192.168.0.4] => {
   "msg": {
       "ansible_facts": {
           "discovered_interpreter_python": "/usr/bin/python"
       },
       "changed": false,
       "failed": false,
       "ping": "pong"
   }
}

PLAY RECAP *********************************************************************
192.168.0.4                : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

ansible-navigator run --helpを実行すると、ansible-playbookと同じオプションサポートするぜ。と表示される。
Note: 'ansible-navigator run' additionally supports the same parameters as the 'ansible-playbook' command. For more information about these, try 'ansible-navigator run --help-playbook --mode stdout'

今回 --ask-passを使いたかったけど、これつけると処理が止まってしまうみたい。

~ $ ansible-navigator run ping.yml -i hosts --ask-pass --mode stdout
-- ここから進まない --
^CTerminated

追記
Githubのansible-navigatorプロジェクトにissue書いたら返信があった。
今度試してみよう。

We have marked this as feature request to automatically detect user is expecting user prompt and disable playbook-artifact creation in stdout mode.

For now as a work around please follow the steps here https://ansible-navigator.readthedocs.io/en/latest/faq/#why-does-the-playbook-hang-when-vars-prompt-or-pause-prompt-is-used to disable the playbook-artifact creation.

この記事が気に入ったらサポートをしてみませんか?