3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【小ネタ】Ansibleでコマンドラインからfactsを確認する【Ansible】

Last updated at Posted at 2019-04-27

はじめに

Ansible Playbookを書く際には、対象ホストのFactsをもとに、when句でTaskを分岐させることが多いと思います。
具体的にホスト上でどのようなFacts情報が取れるか確認しながらPlaybookを書いていきますが、Factを取得する方法を忘れがちなのでメモします。

コマンド

対象ホストにログインしたのち、下記コマンドを実行することでFactsを取得できます

$ ansible localhost -m setup
localhost | SUCCESS => {
    "ansible_facts": {
        "ansible_all_ipv4_addresses": [
            "192.168.255.21",
            "10.0.2.15"
        ],
        "ansible_all_ipv6_addresses": [
            "fe80::a00:27ff:fe6a:71b1",
            "fe80::a00:27ff:feb9:8245"
        ],
        "ansible_apparmor": {
            "status": "disabled"
        },
# ※以降省略

補足

上記コマンドは、第1引数で指定するホストパターンに対して、「setup」モジュールを実行する、という意味になります。
「setup」モジュールのドキュメントは下記にあります。

setup – Gathers facts about remote hosts — Ansible Documentation
https://docs.ansible.com/ansible/latest/modules/setup_module.html

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?