ansible コレクション ファクト未定義変数

ansible コレクション ファクト未定義変数

ホストのいくつかの変数を表示するために事実を収集するためにansibleを使用しようとしています。 ymlファイルです

- name: setup users
  gather_facts: true
  hosts: hosts
  tasks:
    name: display stats after login
    template: 
      src: /stats.j2
      dest: /etc/motd
    become: true

これは jinja2 ファイルです

Arch: {{ hostvars[inventory_hostname]['ansible_architecture'] }}

anisble -m setup によれば、変数は終了しますが、常に変数定義されていないエラーが発生します。

ベストアンサー1

を使用して{{hostvars['inventory_hostname']['...']}}他のホストの情報にアクセスしたくない場合は、テンプレート(stats.j2)を次のように変更できます。

Arch: {{ansible_architecture}}

おすすめ記事