LoginSignup
1
0

ansible導入手順

Last updated at Posted at 2024-03-12

個人的な備忘録です。

流れ

  1. OSインストール(今回は割愛)
  2. OS初期設定(別記事参照)
  3. ansibleインストール
  4. ansible用ユーザ作成
  5. ansible用ユーザ向けSSH公開鍵作成
  6. ansible設定追加
  7. 動作確認

環境

コントロールノード

  • OS:RockyLinux 8.5 
  • Python:Python 3.6.8
  • Ansible: ansible-core 2.15.3
  • ansible用ユーザ名:ansible

ターゲットノード

  • OS:RockyLinux 8.5 
  • Python:Python 3.6.8
  • ansible用ユーザ名:ansible

ansibleインストール

下記コマンドを使ってインストールする

bash
sudo dnf install ansible-core

ansible用ユーザ作成

useraddコマンドで作成する

bash
sudo useradd ansible

作成できたらパスワードも設定する

bash
sudo passwd ansible

ansible用ユーザ向けSSH公開鍵作成

下記コマンドを使ってインストールする

bash
ssh-keygen -t rsa

色々聞かれるが特に設定せずEnter

作成できたらssh公開鍵を交換する

bash
ssh-copy-id -o StrictHostKeyChecking=no -i $HOME/.ssh/id_rsa.pub <ターゲットノードのIPアドレス>

ターゲットホスト側でも鍵生成・交換をおこなう

ansible設定追加

ansibleの設定ファイルにssh接続時のフィンガープリントのチェックを無効にする設定を追加する

/etc/ansible/ansible.cfg
[defaults]
host_key_checking = False

コントローラノード及びターゲットノードの宛先を記載したインベントリファイルを作成する

inventory.ini
localhost
<ターゲットノードのIPアドレス>

動作確認

下記コマンドを使って動作確認をおこなう

bash
ansible -i inventory.ini <ターゲットノードのIPアドレス> -m ansible.builtin.ping

下記の通り動いていれば正常に動作している

bash
[ansible@hogehoge]$ ansible -i inventory.ini <ターゲットノードのIPアドレス> -m ansible.builtin.ping
<ターゲットノードのIPアドレス> | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
1
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
1
0