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 1 year has passed since last update.

Ansible インストール後の環境設定・動作確認

Posted at

Ansibleから各サーバーへSSH接続するための鍵を生成します。

[ansibleuser@localhost ~]$ ssh-keygen -t rsa -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ansibleuser/.ssh/id_rsa):
Created directory '/home/ansibleuser/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ansibleuser/.ssh/id_rsa.
Your public key has been saved in /home/ansibleuser/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:6e4iivhgOo/VB96sXcutaCFVJXceLNFJJKUbn++MfQI ansibleuser@localhost.localdomain
The key's randomart image is:
+---[RSA 4096]----+
|        ..=B*.   |
(省略)
|=++..ooo*.. . +o |
+----[SHA256]-----+

作成された .ssh/id_rsa.pub は接続先サーバーのユーザーの .ssh/authorized_keys に追記しましょう。追記後、鍵を作成した時のパスワードで接続できれは成功です。

[ansibleuser@localhost ~]$ ssh  ansibleuser@192.168.254.101
Enter passphrase for key '/home/ansibleuser/.ssh/id_rsa':
Last login: Sun Jan  9 09:28:04 2022
[ansibleuser@localhost ~]$

次に、ansibleコマンドで接続できるかを確認します。接続先サーバーを設定するhostsファイルを作成します。

[Host003]
192.168.254.101 ansible_user=ansibleuser

ansibleのコマンドで接続してみましょう。

[ansibleuser@localhost ansible]$ ansible -i hosts  Host003 -m shell -a hostname
Enter passphrase for key '/home/ansibleuser/.ssh/id_rsa':
192.168.254.101 | CHANGED | rc=0 >>
localhost.localdomain
[ansibleuser@localhost ansible]$
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?