0
0

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 3 years have passed since last update.

Ansible初期セットアップ

Posted at

前提

  • クライアント: AnsibleはMacにインストール済(ansible 2.10.2)
  • サーバー: VagrantのUbuntu2004の基本的な構築をansibleを使って行うことを想定してます

初期セットアップ

1 logの出力先を準備

$ mkdir logs

2 ansible.cfgファイルの作成

  • remote_user: ansibleを実行するユーザの指定
  • remote_port: defaultは22番ポートだが、今回はvagrant起動時に指定された2222番ポートを使用するため設定
  • private_key_file: ansibleユーザのkeyを指定
  • gathering: ターゲットノードのデータ取得方法の指定
  • host_key_checking: SSH接続時に公開鍵のフィンガープリントをチェックを行うか否か
  • log_path: ansible実行時のログの出力先を指定
diff --git a/ansible.cfg b/ansible.cfg
index 0440d48..3b83cfc 100644
--- a/ansible.cfg
+++ b/ansible.cfg
@@ -1 +1,8 @@
 [defaults]
+
+remote_user = ansible
+remote_port = 2222
+private_key_file = /Users/tshu1/.ssh/id_ed25519_ansible
+gathering = smart
+host_key_checking = False
+log_path = /Users/tshu1/ghq/github.com/tshu1/ubuntu-2004/logs/ansible.log

3 inventoryファイルの作成

$ mkdir inventory

$ vim inventory/vagrant

[ubuntu]
localhost 

4 ansible-galaxyコマンドでroleを作成

$ ansible-galaxy role init base

$ tree
.
├── README.md
├── Vagrantfile
├── ansible.cfg
├── base
│   ├── README.md
│   ├── defaults
│   │   └── main.yml
│   ├── files
│   ├── handlers
│   │   └── main.yml
│   ├── meta
│   │   └── main.yml
│   ├── tasks
│   │   └── main.yml
│   ├── templates
│   ├── tests
│   │   ├── inventory
│   │   └── test.yml
│   └── vars
│       └── main.yml
├── inventory
│   └── vagrant
└── logs
    └── ansible.log

5 接続確認

$ ansible -i inventory ubuntu -m ping
localhost | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python3"
    },
    "changed": false,
    "ping": "pong"
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?