(準備)コントロールノードからマネージドノードにアクセスできるようにする - aktnk/til GitHub Wiki
実施すること
- ansible をインストールしたコントロールノードのユーザ ansible から、マネージドノードにアクセスできるようにする
手順
設定手順
/etc/hostsにマネージドノードのIPアドレスとホスト名を登録する$ sudo nano /etc/hosts 172.168.0.11 ubuntuTest10 172.168.0.12 ubuntuTest11- 設定ファイル
.ansible.cfgにインベントリの定義場所を指定する$ nano .ansible.cfg [defaults] inventory = $HOME/hosts ← ホームディレクトリ直下のhostsファイルにインベントリを定義する hostsファイルにマネージドノードを指定する$ nano hosts [testservers] ubuntuTest10 ubuntuTest11- 正しく設定ができたか確認する
$ ansible all --list-hosts hosts (2): ubuntuTest10 ubuntuTest11
SSHでマネージドノードにアクセスする
- マネージドノードにansibleユーザを作成するの最後に実施したssh公開鍵をマネージドルノードに登録した後、
hostsに指定したホスト名でsshにログインしていなければ、ログインする
ssh ansible@(ホスト名)を実行する$ ssh ansible@ubuntuTest10 The authenticity of host 'ubuntutest10 (172.168.0.11)' can't be established. ED25519 key fingerprint is SHA256:ZYVhr7gdVlcC3K8Gn4STmV5N7HD5BPbKx+hhrxuMR/U. This host key is known by the following other names/addresses: ~/.ssh/known_hosts:1: [hashed name] Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'ubuntutest10' (ED25519) to the list of known hosts. Welcome to Ubuntu 24.04.3 LTS (GNU/Linux 6.14.0-27-generic x86_64) <省略> Last login: Sat Aug 9 12:05:47 2025 from 172.168.0.10 $ exit
動作確認
- 動作確認としてansible からマネージドノードに
pingを実行する
ansible all -m pingを実行する$ ansible all -m ping [WARNING]: Platform linux on host ubuntuTest10 is using the discovered Python interpreter at /usr/bin/python3.12, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible- core/2.17/reference_appendices/interpreter_discovery.html for more information. ubuntuTest10 | SUCCESS => { ← ansibleコマンドによる ping は成功した "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.12" }, "changed": false, "ping": "pong" }
⇒ これでansibleでマネージドノードに指示を出せる準備が整った。