てくなべ (tekunabe)

ansible / network automation / 学習メモ

[Ansible] aws_ec2 インベントリープラグインのinclude_filtersのand/or条件の指定方法

はじめに

AWS上のEC2インスタンスの情報を動的にインベントリとして利用できる、amazon.aws.aws_ec2というインベントリープラグインがあります。

その中に、include_filtersというオプションがあり、Nameタグの情報などで抽出条件を指定できます。

include_filters ということで複数形なので条件も複数指定できるのですが、どう指定すると and なのか or なのか初見では分かりにくかったです。

自分で試してみた結果をまとめます。

  • 環境
    • ansible 5.4.0
    • ansible-core 2.12.3
    • amazon.aws コレクション 2.1.0

前提

EC2 インスタンスは、以下のものがある状態とします。

タグ Name タグ aws:cloudformation:stack-name
sv01a stack01
sv01b stack01
sv01c stack01
sv02a stack02
sv02b stack02
sv02c stack02

CloudFormation のスタック名 stack01stack02 で作成されたインスタンスが3つずつあるような状態です。

or 条件の include_filters

各条件をそれぞれリストで指定すると or 条件になりました。

---
plugin: amazon.aws.aws_ec2
regions:
  - ap-northeast-1
include_filters:
  - tag:Name:
      - sv0*a
  - tag:aws:cloudformation:stack-name:
      - stack01
hostnames:
  - tag:Name

確認します。

$ ansible-inventory -i inventory_aws_ec2.yml --graph
@all:
  |--@aws_ec2:
  |  |--sv01a 
  |  |--sv01b
  |  |--sv01c
  |  |--sv02a
  |--@ungrouped:

Nameで sv0*a を指定しているので該当するインスタンスが2つ抽出されるのに加え、スタック名 stack01 を or 条件で指定しているため、stack01 で作成されたすべてのインスタンスも抽出されたという形です。

and 条件の include_filters

一つのリストの中に複数の条件を指定すると and になりました。

---
plugin: amazon.aws.aws_ec2
regions:
  - ap-northeast-1
include_filters:
  - tag:Name:
      - sv0*a
    tag:aws:cloudformation:stack-name:
      - stack01
hostnames:
  - tag:Name

or 条件のときとの見かけ上の違いは、tag:aws:cloudformation:stack-name の前の - がなくなっただけです。

確認します。

$ ansible-inventory -i inventory_aws_ec2.yml --graph
@all:
  |--@aws_ec2:
  |  |--sv01a
  |--@ungrouped:

今度は、Nameで sv0*a に加えて、and 条件でスタック名 stack01 を指定しています。そのため スタック名 stack01 かつ、Name sv0*a に該当するインスタンスのみが抽出されました。

おわりに

ドキュメント見てもピンとこないときでも、一回試すと腑に落ちたというパターンでした。

[Ansible] 変数を利用する際にクォーテーションで囲う必要がある理由

はじめに

Ansibleもくもく会 2022.5にて、質疑応答を担当するメンターにて参加させていただきました。

"" で書こう意味について質問いただいたので、分かる範囲でお答えしました。その内容についてまとめます。

ディクショナリと区別するために "" で囲う

Playbook 内で、変数の値を展開する場合

- name: debug test
   debug:
     msg: "{{ 変数名 }}"

のように、変数名を{{ }} で囲います。この際 { が値の先頭にくる場合は、クォーテーションで囲う必要があります。囲わないと{ をディクショナリの構文として認識してしまうためです。

この件は、公式ドキュメントに記載されています。

サンプルを引用しますと、以下のケースは "" で囲う必要があります。

- hosts: app_servers
  vars:
      app_path: {{ base_path }}/22    # これはSyntax Error

修正後

- hosts: app_servers
  vars:
       app_path: "{{ base_path }}/22"

以下のケースは、値が { で始まらないため、クォーテーションで囲う必要はありません。

- hosts: app_servers
  vars:
       app_path: /tmp/{{ base_path }}/22   # 問題ない

が、統一して囲うのがいいかもしれません。

- hosts: app_servers
  vars:
       app_path: "/tmp/{{ base_path }}/22"   # これも問題ない

https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#when-to-quote-variables-a-yaml-gotcha

HashiCorp Vault の動的シークレット機能で AWS の一時的 な IAM ユーザーを作成してみた

はじめに

Software Design 2022年5月号の Vault の連載の記事は「動的シークレットで安全性を高めよう」という内容でした。

興味が湧いたので、HashiCorp Learn の Dynamic Secrets も合わせて読んだうえで、試してみました。

AWS の IAM ユーザーの一時的に作成するという内容です。このユーザーの有効期限を短く(デフォルト 768h?、長すぎて検証できず)するためには、少し設定が必要のようでした。その設定をあわせて、私が試してみた内容をまとめます。

AWS シークレットエンジンの有効化

デフォルトでは無効化されているようで、まずは有効化します。

$ vault secrets enable -path=aws aws
Success! Enabled the aws secrets engine at: aws/   # 成功

確認のために vault secrets list を実行した結果は以下のとおりです。

$ vault secrets list
Path          Type         Accessor              Description
----          ----         --------              -----------
aws/          aws          aws_d7104241          n/a
cubbyhole/    cubbyhole    cubbyhole_985a6a5f    per-token private secret storage
identity/     identity     identity_69fd0f2a     identity store
secret/       kv           kv_7e37a4af           key/value secret storage
sys/          system       system_d0a77cbd       system endpoints used for control, policy and debugging

 AWS のアクセスキーとシークレットキーを設定

まず環境変数に AWS のアクセスキーとシークレットキーを設定します。

$ export AWS_ACCESS_KEY_ID=AKIAxxxxxxxxxxxxxxxx
$ export AWS_SECRET_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

設定した環境変数を Vault 側から参照して設定します。

$ vault write aws/config/root \
    access_key=$AWS_ACCESS_KEY_ID \
    secret_key=$AWS_SECRET_ACCESS_KEY \
    region=ap-northeaset-1
Success! Data written to: aws/config/root   # 成功

確認のために vault read aws/config/root を実行した結果は以下のとおりです。

$ vault read  aws/config/root
Key                  Value
---                  -----
access_key           AKIAxxxxxxxxxxxxxxxx
iam_endpoint         n/a
max_retries          -1
region               ap-northeaset-1
sts_endpoint         n/a
username_template    {{ if (eq .Type "STS") }}{{ printf "vault-%s-%s"  (unix_time) (random 20) | truncate 32 }}{{ else }}{{ printf "vault-%s-%s-%s" (printf "%s-%s" (.DisplayName) (.PolicyName) | truncate 42) (unix_time) (random 20) | truncate 64 }}{{ end }}

ロールの作成

次は、一時的に作成される IAM ユーザー に割り当てるロールを作成します。

ここでは、HashiCorp Learn の Dynamic Secretsにあるものを利用させていただきます。

$ vault write aws/roles/my-role \
        credential_type=iam_user \
        policy_document=-<<EOF
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "Stmt1426528957000",
      "Effect": "Allow",
      "Action": [
        "ec2:*"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}
EOF

TTL の変更

検証のため、IAM ユーザーの有効期限を短くします。

通常の TTL を3分、延長できる最長 TTL を 10分にします。(こちらの記事を参考にさせていだきました。)

$ vault write sys/mounts/aws/tune default_lease_ttl=3m max_lease_ttl=10m
Success! Data written to: sys/mounts/aws/tune

(公式ドキュメント上でこの指定の方法を見つけられていません・・)

確認のため、vault read sys/mounts/aws/tune

$ vault read sys/mounts/aws/tune
Key                  Value
---                  -----
default_lease_ttl    3m        # 変更しない場合は 768h
description          n/a
force_no_cache       false
max_lease_ttl        10m       # 変更しない場合は 768h

動的シークレトの取得

いよいよ動的シークレットの取得です。ここでは、つまり 一時的な IAM ユーザーの作成です。

$ vault read aws/creds/my-role
Key                Value
---                -----
lease_id           aws/creds/my-role/ude94KFfvkP5uhv0ZeR1XXeP
lease_duration     3m       # 変更しない場合は 768h
lease_renewable    true
access_key         AKIAyyyyyyyyyyyyyyyy
secret_key         yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy
security_token     <nil>

動作確認

別のターミナルで、先程表示されたアクセスキーとシークレットキーを使って、かんたんな動作確認をします。

EC2 に対するアクス権限があるはずなので aws ec2 describe-instances で一覧表示を試します。

$ aws ec2 describe-instances
{
    "Reservations": [
        {
            "Groups": [],
            "Instances": [
                    "AmiLaunchIndex": 0,
                    "ImageId": "ami-hogehoge",
                    "InstanceId": "i-fugafuga",
# ...(略)...

無事に表示されました。

念のため、許可されていない他の操作ができないことも確認します。

$ aws s3 ls

An error occurred (AccessDenied) when calling the ListBuckets operation: Access Denied

ロールを作成してから3分以内に AWS のネジメントコンソール上で一時的な IAM ユーザーがあることを確認します。

ユーザーが作成された

なるほど。

このまま3分ほど経過すると、vault server -dev でサーバーを起動しているターミナルで以下のログが表示されました。

2022-05-01T18:00:49.945+0900 [INFO]  expiration: revoked lease: lease_id=aws/creds/my-role/ude94KFfvkP5uhv0ZeR1XXeP

IAM ユーザーが削除されたようなので、再度 AWS のネジメントコンソールを確認すると、たしかにいなくなっていました。

削除された

ということは、先程できていた aws ec2 describe-instances はできなくなっているはずなので確認します。

$ aws ec2 describe-instances

An error occurred (AuthFailure) when calling the DescribeInstances operation: AWS was not able to validate the provided access credentials

無事、できなくなっていました。

まとめ

動的シークレットの機能を利用して、AWS の一時的 な IAM ユーザーを作成してみました。

vault lease revoke で明示的に削除もできますが、有効期限で自動削除されるのは安心です。

参考

TTL の設定変更はこちらの記事を参考にさせていただきました。

christina04.hatenablog.com

[AWS] アタッチされていない EBS ボリューム一覧を AWS CLI で表示する

EC2 インスタンス削除時に、自動でEBS ボリュームも削除されるつもりだったのにうっかり残っていた、という経験はありますでしょうか。

このようなとき、アタッチされていない EBS ボリュームの一覧を取得したいときがあるかもしれません(ありました)。

AWS CLI で調べるときのコマンドを控えておきます。

ボリュームの状態が available が「ボリュームはインスタンスにアタッチされていません」とのことなので、--filters オプションで statusavailable なものに絞った上で、 --query オプションで表示項目を調整することにします。

Name タグの値だけ表示したい場合

$ aws ec2 describe-volumes --filters Name=status,Values=available --query 'Volumes[*].Tags[?key==Name].Value[]'
[
    "ugui",
    "oikawa",
    "ginbuna",
    "kinbuna",
    "tanago"
]

ボリュームIDとセットで表示したい場合(キー付き)

$ aws ec2 describe-volumes --filters Name=status,Values=available --query 'Volumes[].{VolumeId: VolumeId, Name: Tags[?key==Name].Value | [0]}'
[
    {
        "VolumeId": "vol-086009cxxxxxxxxxx",
        "Name": "ugui"
    },
    {
        "VolumeId": "vol-01183daxxxxxxxxxx",
        "Name": "oikawa"
    },
    {
        "VolumeId": "vol-0794be4xxxxxxxxxx",
        "Name": "kinbuna"
    },
    {
        "VolumeId": "vol-0a9efabxxxxxxxxxx",
        "Name": "tanago"
    }
]

JMESPath 苦手なので、もう少し良い書き方があるかもしれません。

参考

[ansible] あのモジュール、どのコレクションにいった?を探す

はじめに

Ansible(-base) 2.10 から、多くのモジュールはコレクションという管理、配布方式に移行しました

その関係で「前あったあのモジュール、プラグインはどのコレクションにいったんだ?」と気になることがあるかもしれません。

正確には、しれませんではなく、ありました。

調べた方をまとめておきます。

方法1: リダイレクトの定義ファイルを見る

ansible 本体に、モジュール名のみ(コレクション指定なし)が指定されたときに、どのコレクションのものとして扱うかという、リダイレクトの定義ファイルがあります。

これを見ると、どのコレクションになったのかが分かります。

github.com

インストールした環境にも ansible_builtin_runtime.yml があるはずです。

たとえば、ios_config モジュールであれば、modules 配下の ios_config を探します。

    ios_config:
      redirect: cisco.ios.ios_config

これにより、cisco.ios コレクションのものであることが分かります。

他にもyaml コールバックプラグインであれば、 callback 配下の yaml を探します。

    yaml:
      redirect: community.general.yaml

これにより、community.general コレクションのものであることが分かります。

方法2: ansible-doc で確認する

手元の環境で、移行先のコレクションがインストールされいることが前提ですが、ansible-doc コマンドでも確認できます。

ios_config モジュールの例

$ ansible-doc ios_config
> CISCO.IOS.IOS_CONFIG    (/home/admin/.ansible/collections/ansible_collections/cisco/ios/plugins/modules/ios_config.py)

        Cisco IOS configurations use a simple block indent file syntax for segmenting configuration

callback コールバックプラグインの例

$ ansible-doc -t callback yaml
> COMMUNITY.GENERAL.YAML    (/home/admin/.ansible/collections/ansible_collections/community/general/plugins/callback/yaml.py)

        Ansible output that can be quite a bit easier to read than the default JSON formatting.

-t には以下の値を指定できます (ansible-core 2.12.0の場合)。

  • become
  • cache
  • callback
  • cliconf
  • connection
  • httpapi
  • inventory
  • lookup
  • netconf
  • shell
  • vars,module
  • strategy
  • role
  • keyword

方法3: Playbook 実行時のリダイレクトログで確認する

こちらも手元の環境で、移行先のコレクションがインストールされいることが前提です。

ansible-playbook コマンド実行時に -vv をつけると、以下のようにリダイレクトの様子が見て取れます。

影響を出さないために --check を併用してもいいかもしれません。

redirecting (type: callback) ansible.builtin.yaml to community.general.yaml

記憶が定かではないのですが、一部は -vvv くらいまで付けないと見れなかった気もします。

実行例

$ ansible-playbook -i inventory.ini ios_show.yml -vv
ansible-playbook [core 2.12.4]
  config file = /home/admin/ansible.cfg
  configured module search path = ['/home/admin/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/admin/venv/ansible/lib64/python3.8/site-packages/ansible
  ansible collection location = /home/admin/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/admin/venv/ansible/bin/ansible-playbook
  python version = 3.8.6 (default, Jan 22 2021, 11:41:28) [GCC 8.4.1 20200928 (Red Hat 8.4.1-1)]
  jinja version = 3.0.3
  libyaml = True
Using /home/admin/ansible.cfg as config file
redirecting (type: action) cisco.ios.command to cisco.ios.ios
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
redirecting (type: callback) ansible.builtin.yaml to community.general.yaml
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.

PLAYBOOK: ios_show.yml *******************************************************************************************************************************************
1 plays in ios_show.yml

PLAY [ios1] ******************************************************************************************************************************************************
META: ran handlers
redirecting (type: action) cisco.ios.command to cisco.ios.ios

TASK [aa] ********************************************************************************************************************************************************
task path: /home/admin/ios_show.yml:12
redirecting (type: connection) ansible.builtin.network_cli to ansible.netcommon.network_cli
redirecting (type: terminal) ansible.builtin.ios to cisco.ios.ios
redirecting (type: cliconf) ansible.builtin.ios to cisco.ios.ios
redirecting (type: action) cisco.ios.command to cisco.ios.ios
redirecting (type: action) cisco.ios.command to cisco.ios.ios
redirecting (type: modules) cisco.ios.command to cisco.ios.ios_command
ok: [ios1] => changed=false 
# ...(略)...

[Ansible] ansible-navigator 2.0.0 新機能ピックアップ Part 2: その他編

はじめに

先日、ansible-navigator 2.0.0 がリリースされました。

Release v2.0.0 · ansible/ansible-navigator · GitHub

前回の記事で、追加されたサブコマンドを取り上げました。

tekunabe.hatenablog.jp

今回はそれ以外の気になったものを取り上げます。

(詳細、一覧はリリースノートchangelogを参照してください)

アーティファクトファイル名に含む日時のタイムゾーンを指定可能に

ansible-navigator は Playbook を実行すると、アーティファクトというログをJSON形式で出力できます。

これまではアーティファクトのファイル名の規則として、Playbookのディレクトリ、Playbook名、UTCの時刻を利用できました。

ansible-navigator.yml では以下のように {キー名} で、指定できます。

# ansible-navigator 1.x での設定例
---
ansible-navigator:
  playbook-artifact:
    save-as: "{playbook_dir}/{playbook_name}-artifact-{ts_utc}.json"

時刻は UTC しか指定できませんでしが、ansible-navigator 2.0.0 ではタイムゾーンを指定できるようになりました。

指定できるタイムゾーンの形式は IANA time zone とのことです。この形式の詳細はお恥ずかしながらわかっていませんでしたが、身近なところでは JapanAsia/Tokyo が指定できました。デフォルトは UTC です。

コードを追っていくと、Python 3.9 以上では zoneinfo.ZoneInfo() の引数に渡っていました。

ほか、便利なのがlocal と指定すると、ansible-navigator 自体を実行しているOS側(コンテナの観点ではコンテナホスト)のタイムゾーンに合わせられます。実際はこの指定の仕方が一番多いのではないかと思います。

また、タイムゾーンの指定機能の導入にあわせて、時刻のキー名が ts_utc から time_stamp に変更されました。もし ts_utc のまま実行すると、書き換えるステップをはさみます(後述の設定ファイルの書式変更でも触れます)。

changelog より

タイムゾーン指定の件

Enabled the use of the time_zone settings entry for playbook artifact file name creation.

キー名変更の件

Renamed the ts_utc variable in the playbook artifact file name to time_stamp.

以下は、ansible-navigator.yml で、アーティファクトファイル名にタイムスタンプを含め、OS 側のタイムゾーンに合わせる設定例です。

---
ansible-navigator:
  playbook-artifact:
    enable: true    # デフォルト
    save-as: "{playbook_dir}/{playbook_name}-artifact-{time_stamp}.json"  # デフォルト
  time-zone: local  # OS設定に合わせる

OS側のタイムゾーンAsia/Tokyo の場合、playbook-artifact-2022-04-19T20:58:29.302037+09:00.json のようなアーティファクトが生成されます。+09:00 になります。

なお、この機能は私が issue を書いてご対応いただきました。 @cidrblock Thank you!



images サブコマンドが stdout モードでも利用可能に

images サブコマンドは、実行環境内の OS、Ansible バージョン、コレクション、Python パッケージのの情報を表示できる機能です。機能自体は以前からありましたが、 interactive モードのみのサポートでした。今回、stdout モードにも対応しました。

changelogから

Added basic support for mode stdout for the images subcommand.

その場でちょっと確認するだけでしたら interactive モードが便利かもしれません。

一方、出力結果をファイルに保存したり、抽出、加工する場合は stdout モードが適していそうです。

コマンドで stdout モードを指定する場合は、--mode stdout を指定します。詳細情報を特に指定しない場合は、実行環境の概要情報が表示されます。

ansible-navigator.yml がない状態で実行したら、以下の3つの環境が表示されました。

$ ansible-navigator images --mode stdout
---
- created: 2 days ago
  execution_environment: true
  full_name: quay.io/ansible/ansible-runner:latest
  image_id: 84f0acda4cea
  inspect:
# ...(略)...
- created: 4 months ago
  execution_environment: true
  full_name: quay.io/ansible/ansible-runner:stable-2.12-devel
  image_id: 8eb88c5bd9fb
  inspect:
# ...(略)...
- created: 2 weeks ago
  execution_environment: true
  full_name: quay.io/ansible/creator-ee:v0.4.2
  image_id: 12571ac947cf
  inspect:
# ...(略)...

詳細情報の表示

-d または --details をプションを指定すると、更に詳細情報を表示できます。詳細情報は以下の種類種類をさらに指定できます。デフォルトは everything です。

  • ansible_collections
  • ansible_version
  • everything
  • os_release
  • python_packages
  • python_version
  • redhat_release
  • system_packages

例えば、ansible_versionansible_collections に絞って表示したい場合は以下のように指定します。

$ ansible-navigator images -d ansible_version -d ansible_collections
---
ansible_collections:
  details:
    amazon.aws: 3.1.1
    ansible.posix: 1.3.0
    ansible.windows: 1.9.0
    awx.awx: 20.1.0
    azure.azcollection: 1.12.0
    community.docker: 2.3.0
    community.vmware: 2.2.0
    containers.podman: 1.9.3
    google.cloud: 1.0.2
    kubernetes.core: 2.3.0
    openstack.cloud: 1.7.2
    ovirt.ovirt: 1.6.6
    redhatinsights.insights: 1.0.7
    theforeman.foreman: 3.2.0
ansible_version:
  details: ansible [core 2.12.4.post0]
image_name: quay.io/ansible/creator-ee:v0.4.2

イメージを指定したい場合は、--eei オプションも指定します。

$ ansible-navigator images --eei イメージ名 -d ansible_version -d ansible_collections 

他、collections サブコマンドも、stdout モードでも利用可能になりました。

参考: images サブコマンドのヘルプ

ansible-navigator images -h の結果(クリックして開く)

$ ansible-navigator images -h
Usage: ansible-navigator images [options]

images: Explore execution environment images

Options (global):
 -h     --help                                   Show this help message and exit
 --version                                       Show the application version and
                                                 exit
 --rad  --ansible-runner-artifact-dir            The directory path to store
                                                 artifacts generated by ansible-
                                                 runner
 --rac  --ansible-runner-rotate-artifacts-count  Keep ansible-runner artifact
                                                 directories, for last n runs, if set
                                                 to 0 artifact directories won't be
                                                 deleted
 --rt   --ansible-runner-timeout                 The timeout value after which
                                                 ansible-runner will forcefully stop
                                                 the execution
 --cdcp --collection-doc-cache-path              The path to collection doc cache
                                                 (default:
                                                 /home/admin/.cache/ansible-
                                                 navigator/collection_doc_cache.db)
 --ce   --container-engine                       Specify the container engine
                                                 (auto=podman then docker)
                                                 (auto|podman|docker) (default: auto)
 --co   --container-options                      Extra parameters passed to the
                                                 container engine command
 --dc   --display-color                          Enable the use of color for mode
                                                 interactive and stdout (true|false)
                                                 (default: true)
 --ecmd --editor-command                         Specify the editor command (default:
                                                 vi +{line_number} {filename})
 --econ --editor-console                         Specify if the editor is console
                                                 based (true|false) (default: true)
 --ee   --execution-environment                  Enable or disable the use of an
                                                 execution environment (true|false)
                                                 (default: true)
 --eei  --execution-environment-image            Specify the name of the execution
                                                 environment image (default:
                                                 quay.io/ansible/creator-ee:v0.4.2)
 --eev  --execution-environment-volume-mounts    Specify volume to be bind mounted
                                                 within an execution environment
                                                 (--eev
                                                 /home/user/test:/home/user/test:Z)
 --la   --log-append                             Specify if log messages should be
                                                 appended to an existing log file,
                                                 otherwise a new log file will be
                                                 created per session (true|false)
                                                 (default: true)
 --lf   --log-file                               Specify the full path for the
                                                 ansible-navigator log file (default:
                                                 /home/admin/git/general/vagrant/nwla
                                                 b/ee/ansible-navigator.log)
 --ll   --log-level                              Specify the ansible-navigator log
                                                 level
                                                 (debug|info|warning|error|critical)
                                                 (default: warning)
 -m     --mode                                   Specify the user-interface mode
                                                 (stdout|interactive) (default:
                                                 interactive)
 --osc4 --osc4                                   Enable or disable terminal color
                                                 changing support with OSC 4
                                                 (true|false) (default: true)
 --penv --pass-environment-variable              Specify an existing environment
                                                 variable to be passed through to and
                                                 set within the execution environment
                                                 (--penv MY_VAR)
 --pa   --pull-arguments                         Specify any additional parameters
                                                 that should be added to the pull
                                                 command when pulling an execution
                                                 environment from a container
                                                 registry. e.g. --pa='--tls-
                                                 verify=false'
 --pp   --pull-policy                            Specify the image pull policy
                                                 always:Always pull the image,
                                                 missing:Pull if not locally
                                                 available, never:Never pull the
                                                 image, tag:if the image tag is
                                                 'latest', always pull the image,
                                                 otherwise pull if not locally
                                                 available (always|missing|never|tag)
                                                 (default: tag)
 --senv --set-environment-variable               Specify an environment variable and
                                                 a value to be set within the
                                                 execution environment (--senv
                                                 MY_VAR=42)
 --tz   --time-zone                              Specify the IANA time zone to use or
                                                 'local' to use the system time zone
                                                 (default: utc)

Options (images subcommand):
 -d     --details                                Provide detailed information about
                                                 the selected execution environment
                                                 image (ansible_collections|ansible_v
                                                 ersion|everything|os_release|python_
                                                 packages|python_version|redhat_relea
                                                 se|system_packages) (default:
                                                 ['everything'])



■ 設定ファイルの JSON Schema によるチェック

ansible-navigator run などの各処理の実行前に、ansible-navigator.yml などの設定ファイルJSON Schema によるチェックが行われるようになりました。

changelogから

Added settings file validation against the settings file JSON Schema during application initialization.

これまでは、設定ファイルにスペルミスなどの不備があった場合は、無視して処理が続行されていました。事前にチェックが入ることにより、意図しない挙動を未然に防げそうです。

例えば、以下の ansible-navigator.yml では environment のスペルを間違えています。

---
ansible-navigator:
  execution-enviroment:     # environment がスペルミス
    enabled: true
    image: localhost/my-ee:latest 

この状態で、書式チェックするために単に ansible-navigator とだけ実行すると、以下のようなエラーが表示されます。

$ ansible-navigator
Warning: Issues were found while applying the settings.
   Hint: Command provided: ''

  Error: The following errors were found in the settings file (/home/admin/git/general/vagrant/nwlab/ee/ansible-navigator.yml):
         In 'ansible-navigator': Additional properties are not allowed ('execution-enviroment' was unexpected).
   Hint: Check the settings file and compare it to the current version.
         The current version can be found here:
         (https://ansible-navigator.readthedocs.io/en/latest/settings/#ansible-navigator-settings)
         The schema used for validation can be seen with 'ansible-navigator settings --schema'
         A sample settings file can be created with 'ansible-navigator settings --sample'

   Note: Configuration failed, using default log file location. (/home/admin/git/general/vagrant/nwlab/ee/ansible-navigator.log) Log
         level set to debug
   Hint: Review the hints and log file to see what went wrong.

'execution-enviroment' was unexpected とあるので、すぐに気づけます。もし問題なければ、この場合は Welcome 画面が開きます。

一方、以前の バージョンの ansible-navigator では、書式エラーは無視され、デフォルトの設定で処理を続行しようとしてしまいます。

書式エラーで早い段階で止まってくれるのは安心です。

参考: VSCode による書式チェック

書式チェックの方法としては、VS CodeYAML という拡張を利用するというアプローチもあります。

そうすると、ansible-navigator.yml 以下のように、書式エラーが表示されます。

スペルミスを検出

また、この拡張によって各設定項目の入力候補も表示されるため、とても便利です。

便利な補完機能



■ 設定ファイルの書式変更

設定ファイル(ansible-navigator.yml)の一部の書式が変更されました。

旧書式を新書式の対応を示したサンプルは以下のとおりです。コメントアウトした旧書式Nと新書式Nが対応しています。

---
ansible-navigator:
  execution-environment:
    # 旧書式1
    # pull-policy: missing

    # 新書式1
    pull:
      policy: missing

  # 旧書式2
  # documentation:
  #   plugin:
  #     name: service
  #     type: module

  ansible:
    # 新書式2
    doc:
      plugin:
        name: service
        type: module

    # 旧書式3
    # playbook: hoge.yml
    # config: ansible.cfg
    # inventories: 
    #   - inventory.yml

    # 新書式3
    playbook:
      path: hoge.yml
    config:
      path: ansible.cfg
    inventory:
      entries:
        - inventory.yml

新書式のほうが、きれいに階層化された印象があります。

他にも、ヘルプ系の設定項目も書式変更があります。詳細は changelog を参照してください。

Moved the help entries into their respective ansible command parent keys in settings file.

新書式への移行機能

ansible-navigator 実行時に、以前のままの書式が検出された場合、新しい書式に移行(書き換え)するかどうか選択できます。

$ ansible-navigator 

The following version migrations are required:
  - Version 1 to Version 2 settings file format migration
Do you want to run them all? (Y/n): Y       # 書き換えする場合は Y

Version 1 to Version 2 settings file format migration:
Migration of 'config path'..................................Not needed
Migration of 'documentation'................................Updated     # 書き換わった
Migration of 'playbook path'................................Not needed
Migration of 'help builder'.................................Not needed
Migration of 'help config'..................................Not needed
Migration of 'help doc'.....................................Not needed
Migration of 'help inventory'...............................Not needed
Migration of 'help playbook'................................Not needed
Migration of 'inventory paths'..............................Not needed
Migration of 'playbook artifact timestamp'..................Not needed
Migration of 'pull-policy'..................................Not needed
Migration of 'volume mount labels'..........................Not needed
Backup: /home/admin/git/general/vagrant/nwlab/ee/ansible-navigator.v1
Updated: /home/admin/git/general/vagrant/nwlab/ee/ansible-navigator.yml

Migration complete

Press Enter to continue:    # 処理を続けるには Enter

書き換え前のファイルは ansible-navigator.v1 としてバックアップされますので、不要であれば削除します。



Python 3.8 以上が要件に

Python 3.6 と 3.7 がサポートから外され、Python 3.8 以上が要件になりました。

changelogから

Set the minimum supported python version for ansible-navigator to 3.8.

関連PR

github.com



■ 実行環境イメージpull時のオプションを指定可能に

ansible-navigator コマンドに、実行環境イメージpull時のオプションを指定できる --pa--pull-arguments オプションが利用できるようになりました。

たとえば、--pa='--tls-verify=false' と指定することで、podman pull 時に証明書検証を無効にする指定もできるようです。

  • ansible-navigator -h から抜粋
 --pa   --pull-arguments                         Specify any additional parameters that should be added
                                                 to the pull command when pulling an execution
                                                 environment from a container registry. e.g. --pa='--
                                                 tls-verify=false'


■ デフォルトの実行イメージが変更

pip でインストールした ansible-navigator 1.1.0 では quay.io/ansible/ansible-navigator-demo-ee:0.6.0 でしたが quay.io/ansible/creator-ee:v0.4 に変更されました。

changelog より

Upgraded default execution environment image to creator-ee:v0.4.0


おわりに

前回に続いて、ansible-navigator 2.0.0 の機能で気になったポイントを取り上げました。

いろいろと機能が追加されて、これかの発展も楽しみなツールです。

参考

リリースノート

github.com

changelog

ansible-navigator.readthedocs.io

[Ansible] ansible-navigator 2.0.0 機能ピックアップ Part 1: 追加サブコマンド編

はじめに

先日、ansible-navigator 2.0.0 がリリースされました。

github.com

ansible-navigator は、Playbook 実行や実行環境の管理などの機能を持つ TUI ツールです。

2.0.0 では、実行環境のビルドや ansible-lint を呼び出す機能などの追加や、設定ファイル(ansible-navigator.yml)の書式変更、Python 3.6 と 3.7 のサポート停止がされました。

この記事ですが、追加されたサブコマンド(機能)について取り上げます。

(詳細はリリースノートchangelogを参照してください)

※その他の機能追加や、変更点については後日別の記事にする予定です。 [2022/04/19 追記] その他編として投稿しました。

[Ansible] ansible-navigator 2.0.0 新機能ピックアップ Part 2: その他編 - てくなべ (tekunabe)

■ 1. settings サブコマンド追加 (設定内容の確認)

ansible-navigator は ansible-navigator サブコマンド という形で実行します。サブコマンドによって挙動が大きく変わります(サブコマンド一覧はこちら)。

ansible-navigator 2.0.0 ではいくつかのサブコマンドが追加されました。stettings もその一つです。

settings サブコマンドは ansible-navigator 自身の設定の状態確認できます。

changelog より

Added new subcommand :settings to output all current ansible-navigator settings to the menu or to standard output.

設定は ansible-navigator.yml環境変数などによって決まります。

  • ansible-navigator settings 実行結果

ansible-navigator settings コマンドの実行結果

設定の状態確認だけでなく、設定項目の番号は 数字1桁 または :数字1桁以上 エンター で指定すると、各設定のヘルプドキュメントも確認できます。

Container engine の詳細

設定項目はそれなりの数があるため、覚えるのも難しいです。そのため、公式ドキュメントのページを参照しますが、ansible-navigator setting からターミナル上で各設定項目の意味や指定できる値を選択できるのは便利だと思います。

なお、setting サブコマンドは、interactive (TUI)モードだけでなく stdout モードでの表示にも対応しています。コマンドの引数で指定する場合、-m stdout を追加で指定します。

$ ansible-navigator settings -m stdout
---
- choices: []
  cli_parameters:
    long: --ansible-runner-artifact-dir
    short: --rad
  current_settings_file: None
  current_value: Not set
  default: true
  default_value: Not set
  description: The directory path to store artifacts generated by ansible-runner
  env_var: ANSIBLE_NAVIGATOR_ANSIBLE_RUNNER_ARTIFACT_DIR
  name: Ansible runner artifact dir
  settings_file_sample:
    ansible-navigator:
      ansible-runner:
        artifact-dir: <------
  source: Not set
  subcommands:
# ...(略)...

参考: settings サブコマンドのヘルプ

ansible-navigator settings --help の結果(クリックして開く)

$ ansible-navigator settings --help
Usage: ansible-navigator settings [options]

settings: Review the current ansible-navigator settings

Options (global):
 -h     --help                                   Show this help message and exit
 --version                                       Show the application version and exit
 --rad  --ansible-runner-artifact-dir            The directory path to store artifacts generated by ansible-runner
 --rac  --ansible-runner-rotate-artifacts-count  Keep ansible-runner artifact directories, for last n runs, if set to 0 artifact directories won't be deleted
 --rt   --ansible-runner-timeout                 The timeout value after which ansible-runner will forcefully stop the execution
 --cdcp --collection-doc-cache-path              The path to collection doc cache (default: /home/admin/.cache/ansible-navigator/collection_doc_cache.db)
 --ce   --container-engine                       Specify the container engine (auto=podman then docker) (auto|podman|docker) (default: auto)
 --co   --container-options                      Extra parameters passed to the container engine command
 --dc   --display-color                          Enable the use of color for mode interactive and stdout (true|false) (default: true)
 --ecmd --editor-command                         Specify the editor command (default: vi +{line_number} {filename})
 --econ --editor-console                         Specify if the editor is console based (true|false) (default: true)
 --ee   --execution-environment                  Enable or disable the use of an execution environment (true|false) (default: true)
 --eei  --execution-environment-image            Specify the name of the execution environment image (default: quay.io/ansible/creator-ee:v0.4.2)
 --eev  --execution-environment-volume-mounts    Specify volume to be bind mounted within an execution environment (--eev /home/user/test:/home/user/test:Z)
 --la   --log-append                             Specify if log messages should be appended to an existing log file, otherwise a new log file will be created per
                                                 session (true|false) (default: true)
 --lf   --log-file                               Specify the full path for the ansible-navigator log file (default: /home/admin/git/general/ansible-
                                                 navigator.log)
 --ll   --log-level                              Specify the ansible-navigator log level (debug|info|warning|error|critical) (default: warning)
 -m     --mode                                   Specify the user-interface mode (stdout|interactive) (default: interactive)
 --osc4 --osc4                                   Enable or disable terminal color changing support with OSC 4 (true|false) (default: true)
 --penv --pass-environment-variable              Specify an existing environment variable to be passed through to and set within the execution environment
                                                 (--penv MY_VAR)
 --pa   --pull-arguments                         Specify any additional parameters that should be added to the pull command when pulling an execution environment
                                                 from a container registry. e.g. --pa='--tls-verify=false'
 --pp   --pull-policy                            Specify the image pull policy always:Always pull the image, missing:Pull if not locally available, never:Never
                                                 pull the image, tag:if the image tag is 'latest', always pull the image, otherwise pull if not locally available
                                                 (always|missing|never|tag) (default: tag)
 --senv --set-environment-variable               Specify an environment variable and a value to be set within the execution environment (--senv MY_VAR=42)
 --tz   --time-zone                              Specify the IANA time zone to use or 'local' to use the system time zone (default: utc)

Options (settings subcommand):
 --se   --effective                              Show the effective settings. Defaults, CLI parameters, environment variables, and the settings file will be
                                                 combined
 --gs   --sample                                 Generate a sample settings file
 --ss   --schema                                 Generate a schema for the settings file ('json'= draft-07 JSON Schema) (json) (default: json)
 --so   --sources                                Show the source of each current settings entry



■ 2. builder サブコマンド追加 (ansible-builder 呼び出し)

実行環境のイメージをビルドするツールとして ansible-builder があります。

ansible-navigator builder コマンド経由で、ansible-builder を呼べるようになりました。ansible-navigator をインストールすると、ansible-builder も一緒にインストールされます。

例えば、ansible-builder build に相当するコマンドは ansible-navigator builder build です。

対応の一覧は以下の通りです。

ansible-builder 直のコマンド ansible-navigator 経由のコマンド
ansible-builder create オプション ansible-navigator builder create オプション
ansible-builder build オプション ansible-navigator builder build オプション
ansible-builder introspect オプション ansible-navigator builder introspect オプション

createbuildintrospec の意味は ansible-navigator builder コマンド用のヘルプで確認できます。

$ ansible-navigator builder --help-builder
usage: ansible-builder [-h] [--version] {create,build,introspect} ...

Tooling to help build container images for running Ansible content. Get started by looking at the help text for one of the subcommands.

positional arguments:
  {create,build,introspect}
                        The command to invoke.
    create              Creates a build context, which can be used by podman to build an image.
    build               Builds a container image.
    introspect          Introspects collections in folder.

optional arguments:
  -h, --help            show this help message and exit
  --version             Print ansible-builder version and exit.

参考: builder サブコマンドのヘルプ

指定できるオプションは ansible-navigator builder --help を実行するといろいろ確認できます。

ansible-navigator builder --help の結果(クリックして開く)

$ ansible-navigator builder --help
Usage: ansible-navigator builder [options]

builder: Build execution environment (container image)

Options (global):
 -h     --help                                   Show this help message and exit
 --version                                       Show the application version and exit
 --rad  --ansible-runner-artifact-dir            The directory path to store artifacts generated by ansible-runner
 --rac  --ansible-runner-rotate-artifacts-count  Keep ansible-runner artifact directories, for last n runs, if set to 0 artifact directories won't be deleted
 --rt   --ansible-runner-timeout                 The timeout value after which ansible-runner will forcefully stop the execution
 --cdcp --collection-doc-cache-path              The path to collection doc cache (default: /home/admin/.cache/ansible-navigator/collection_doc_cache.db)
 --ce   --container-engine                       Specify the container engine (auto=podman then docker) (auto|podman|docker) (default: auto)
 --co   --container-options                      Extra parameters passed to the container engine command
 --dc   --display-color                          Enable the use of color for mode interactive and stdout (true|false) (default: true)
 --ecmd --editor-command                         Specify the editor command (default: vi +{line_number} {filename})
 --econ --editor-console                         Specify if the editor is console based (true|false) (default: true)
 --ee   --execution-environment                  Enable or disable the use of an execution environment (true|false) (default: true)
 --eei  --execution-environment-image            Specify the name of the execution environment image (default: quay.io/ansible/creator-ee:v0.4.2)
 --eev  --execution-environment-volume-mounts    Specify volume to be bind mounted within an execution environment (--eev /home/user/test:/home/user/test:Z)
 --la   --log-append                             Specify if log messages should be appended to an existing log file, otherwise a new log file will be created per
                                                 session (true|false) (default: true)
 --lf   --log-file                               Specify the full path for the ansible-navigator log file (default: /home/admin/git/general/ansible-
                                                 navigator.log)
 --ll   --log-level                              Specify the ansible-navigator log level (debug|info|warning|error|critical) (default: warning)
 -m     --mode                                   Specify the user-interface mode (stdout|interactive) (default: interactive)
 --osc4 --osc4                                   Enable or disable terminal color changing support with OSC 4 (true|false) (default: true)
 --penv --pass-environment-variable              Specify an existing environment variable to be passed through to and set within the execution environment
                                                 (--penv MY_VAR)
 --pa   --pull-arguments                         Specify any additional parameters that should be added to the pull command when pulling an execution environment
                                                 from a container registry. e.g. --pa='--tls-verify=false'
 --pp   --pull-policy                            Specify the image pull policy always:Always pull the image, missing:Pull if not locally available, never:Never
                                                 pull the image, tag:if the image tag is 'latest', always pull the image, otherwise pull if not locally available
                                                 (always|missing|never|tag) (default: tag)
 --senv --set-environment-variable               Specify an environment variable and a value to be set within the execution environment (--senv MY_VAR=42)
 --tz   --time-zone                              Specify the IANA time zone to use or 'local' to use the system time zone (default: utc)

Options (builder subcommand):
 --hb   --help-builder                           Help options for ansible-builder command in stdout mode (true|false)
 --bwd  --workdir                                Specify the path that contains ansible-builder manifest files (default: /home/admin/git/general)

Note: 'ansible-navigator builder' additionally supports the same parameters as the 'ansible-builder' command. For more information about these, try 'ansible-
navigator builder --help-builder --mode stdout'

最後の行に、

Note: 'ansible-navigator builder' additionally supports the same parameters as the 'ansible-builder' command.

とあるように、ansible-builder で指定できるオプションはそのまま ansible-navigator builder でも指定できるようです。ansible-builder のオプションの詳細は ansible-builder 側の公式ドキュメントを参照してください。



■ 3. exec サブコマンド追加(実行環境コンテナ内のコマンド実行)

ansible-navigator exec 実行したいコマンド で、実行環境コンテナ内に対してコマンドを実行できるようになりました。ちょっとした調べごとなどに便利かも知れません。

exec の後に指定するコマンドのデフォルトは /bin/bash です。単に ansible-navigator exec を実行すると、シェルに入れます。

$ ansible-navigator exec
bash-4.4# uname -a   # 適当に実行してみる
Linux 6a66a85e44f7 4.18.0-305.el8.x86_64 #1 SMP Thu Apr 29 08:54:30 EDT 2021 x86_64 x86_64 x86_64 GNU/Linux
bash-4.4# whoami  
root
bash-4.4# ansible --version
ansible [core 2.12.4.post0]
...()...

実行したいコマンドも合わせて指定すると、そのコマンドの実行結果だけが返ってきます。

$ ansible-navigator exec whoami
root

コマンド書式上、コマンドにスペースを含む場合はクォーテーションで囲う必要があります。

$ ansible-navigator exec "ansible --version | grep core"
ansible [core 2.12.4.post0

別途、-- で区切る方法もあります。

$ ansible-navigator exec -- ansible --version | grep core
ansible [core 2.12.4.post0]

ただのラッパーではない

exec サブコマンドは、ただの podman rundocker run のラッパーというわけではないようで、ansible-navigator の仕様に基づいてマウントなどもしてくれます。

podman inspect で詳細を確認すると、Mounts 配下の情報からバインドマウントしてる様子が確認できました。(抜粋部分はSSH キーのマウントの仕様によるもの)

// ...(略)...
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/home/admin/.ssh",
                "Destination": "/home/runner/.ssh",
                "Driver": "",
                "Mode": "",
                "Options": [
                    "rbind"
                ],
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/home/admin/.ssh",
                "Destination": "/root/.ssh",
                "Driver": "",
                "Mode": "",
                "Options": [
                    "rbind"
                ],
                "RW": true,
                "Propagation": "rprivate"
            },
// ...(略)...

参考: exec サブコマンドのヘルプ

ansible-navigator exec --help 結果(クリックして開く)

$ ansible-navigator exec --help
Usage: ansible-navigator exec [options]

exec: Run a command within an execution environment

Options (global):
 -h     --help                                   Show this help message and exit
 --version                                       Show the application version and exit
 --rad  --ansible-runner-artifact-dir            The directory path to store artifacts generated by ansible-runner
 --rac  --ansible-runner-rotate-artifacts-count  Keep ansible-runner artifact directories, for last n runs, if set to 0 artifact directories won't be deleted
 --rt   --ansible-runner-timeout                 The timeout value after which ansible-runner will forcefully stop the execution
 --cdcp --collection-doc-cache-path              The path to collection doc cache (default: /home/admin/.cache/ansible-navigator/collection_doc_cache.db)
 --ce   --container-engine                       Specify the container engine (auto=podman then docker) (auto|podman|docker) (default: auto)
 --co   --container-options                      Extra parameters passed to the container engine command
 --dc   --display-color                          Enable the use of color for mode interactive and stdout (true|false) (default: true)
 --ecmd --editor-command                         Specify the editor command (default: vi +{line_number} {filename})
 --econ --editor-console                         Specify if the editor is console based (true|false) (default: true)
 --ee   --execution-environment                  Enable or disable the use of an execution environment (true|false) (default: true)
 --eei  --execution-environment-image            Specify the name of the execution environment image (default: quay.io/ansible/creator-ee:v0.4.2)
 --eev  --execution-environment-volume-mounts    Specify volume to be bind mounted within an execution environment (--eev /home/user/test:/home/user/test:Z)
 --la   --log-append                             Specify if log messages should be appended to an existing log file, otherwise a new log file will be created per
                                                 session (true|false) (default: true)
 --lf   --log-file                               Specify the full path for the ansible-navigator log file (default: /home/admin/git/general/ansible-
                                                 navigator.log)
 --ll   --log-level                              Specify the ansible-navigator log level (debug|info|warning|error|critical) (default: warning)
 -m     --mode                                   Specify the user-interface mode (stdout|interactive) (default: interactive)
 --osc4 --osc4                                   Enable or disable terminal color changing support with OSC 4 (true|false) (default: true)
 --penv --pass-environment-variable              Specify an existing environment variable to be passed through to and set within the execution environment
                                                 (--penv MY_VAR)
 --pa   --pull-arguments                         Specify any additional parameters that should be added to the pull command when pulling an execution environment
                                                 from a container registry. e.g. --pa='--tls-verify=false'
 --pp   --pull-policy                            Specify the image pull policy always:Always pull the image, missing:Pull if not locally available, never:Never
                                                 pull the image, tag:if the image tag is 'latest', always pull the image, otherwise pull if not locally available
                                                 (always|missing|never|tag) (default: tag)
 --senv --set-environment-variable               Specify an environment variable and a value to be set within the execution environment (--senv MY_VAR=42)
 --tz   --time-zone                              Specify the IANA time zone to use or 'local' to use the system time zone (default: utc)

Options (exec subcommand):
 exec_command                                    Specify the command to run within the execution environment (default: /bin/bash)
 --exshell --exec-shell                          Specify the exec command should be run in a shell (true|false) (default: true)

Note: During development, it may become necessary to interact directly with the execution environment to review and confirm its build and behavior. All navigator
settings will be applied when starting the execution environment.



■ 4. lint サブコマンド追加 (ansible-lintの呼び出し)

ansible-navigator lint で、ansible-lint を呼び出せるようになりました。

ansible-navigator lint で ansible-lint の呼び出し

行頭の番号を数字1桁 または :数字1桁以上 エンター で指定すると、詳細が表示されます。

エラーや警告類の詳細表示

実行環境の利用が有効(デフォルト)の場合は、実行環境内の ansible-lint が呼び出されます。今回の場合は、デフォルトの実行環境のイメージ quay.io/ansible/creator-ee:v0.4.2 内の ansible-lint 6.0.2 と yamllint 1.26.3 が利用されました。

逆に、実行環境の利用が無効(--ee false 等による指定)の場合は、ホスト側(ansible-navigator 自身を実行している側)の ansible-lint を呼び出します。ただし、ansible-navigator インストール時には ansible-lint はセットでインストールされないため、別途インストールする必要があります。

stdout モードによる実行にも対応しています。こちらのほうが馴染み深いでしょうか。

$ ansible-navigator lint -m stdout
WARNING: PATH altered to include /usr/bin
yaml: truthy value should be one of [false, true] (truthy)
playbook.yml:2

fqcn-builtins: Use FQCN for builtin actions.
playbook.yml:6 Task/Handler: debug msg=hello

unnamed-task: All tasks should be named.
playbook.yml:6 Task/Handler: debug msg=hello

yaml: no new line character at the end of file (new-line-at-end-of-file)
playbook.yml:7

参考: lint サブコマンドのヘルプ

ansible-navigator lint --help 結果(クリックして開く)

$ ansible-navigator lint --help
Usage: ansible-navigator lint [options]

lint: Lint a file or directory for common errors and issues

Options (global):
 -h     --help                                   Show this help message and exit
 --version                                       Show the application version and exit
 --rad  --ansible-runner-artifact-dir            The directory path to store artifacts generated by ansible-runner
 --rac  --ansible-runner-rotate-artifacts-count  Keep ansible-runner artifact directories, for last n runs, if set to 0 artifact directories won't be deleted
 --rt   --ansible-runner-timeout                 The timeout value after which ansible-runner will forcefully stop the execution
 --cdcp --collection-doc-cache-path              The path to collection doc cache (default: /home/admin/.cache/ansible-navigator/collection_doc_cache.db)
 --ce   --container-engine                       Specify the container engine (auto=podman then docker) (auto|podman|docker) (default: auto)
 --co   --container-options                      Extra parameters passed to the container engine command
 --dc   --display-color                          Enable the use of color for mode interactive and stdout (true|false) (default: true)
 --ecmd --editor-command                         Specify the editor command (default: vi +{line_number} {filename})
 --econ --editor-console                         Specify if the editor is console based (true|false) (default: true)
 --ee   --execution-environment                  Enable or disable the use of an execution environment (true|false) (default: true)
 --eei  --execution-environment-image            Specify the name of the execution environment image (default: quay.io/ansible/creator-ee:v0.4.2)
 --eev  --execution-environment-volume-mounts    Specify volume to be bind mounted within an execution environment (--eev /home/user/test:/home/user/test:Z)
 --la   --log-append                             Specify if log messages should be appended to an existing log file, otherwise a new log file will be created per session (true|false)
                                                 (default: true)
 --lf   --log-file                               Specify the full path for the ansible-navigator log file (default: /home/admin/git/general/ansible-navigator.log)
 --ll   --log-level                              Specify the ansible-navigator log level (debug|info|warning|error|critical) (default: warning)
 -m     --mode                                   Specify the user-interface mode (stdout|interactive) (default: interactive)
 --osc4 --osc4                                   Enable or disable terminal color changing support with OSC 4 (true|false) (default: true)
 --penv --pass-environment-variable              Specify an existing environment variable to be passed through to and set within the execution environment (--penv MY_VAR)
 --pa   --pull-arguments                         Specify any additional parameters that should be added to the pull command when pulling an execution environment from a container registry.
                                                 e.g. --pa='--tls-verify=false'
 --pp   --pull-policy                            Specify the image pull policy always:Always pull the image, missing:Pull if not locally available, never:Never pull the image, tag:if the
                                                 image tag is 'latest', always pull the image, otherwise pull if not locally available (always|missing|never|tag) (default: tag)
 --senv --set-environment-variable               Specify an environment variable and a value to be set within the execution environment (--senv MY_VAR=42)
 --tz   --time-zone                              Specify the IANA time zone to use or 'local' to use the system time zone (default: utc)

Options (lint subcommand):
 --lic  --lint-config                            Specify the path to the ansible-lint configuration file
 lintables                                       Path to files on which to run ansible-lint

Note: Defaults to the current working directory. If using an execution environment, ansible-lint must be installed in it. If not using an execution environment, ansible-lint must be installed
on your system.


おわりに

ansible-navigator 2.0.0 では、サブコマンドが追加されて、 ansible-lint も ansible-builder も ansible-navigator コマンド経由で呼べるようになりました。

もしかしたら手癖でとりあえず、ansible-navigator と入力するようになるかもしれません。

その他の機能追加や、仕様変更は別の記事にする予定です。 [2022/04/19 追記] その他編として投稿しました。

tekunabe.hatenablog.jp

参考

リリースノート

github.com

changelog

ansible-navigator.readthedocs.io