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.

CentOS7でさくっとansibleインストール&動作確認

Last updated at Posted at 2023-01-30

はじめに

小難しいこと抜きでさくっとやる

コマンド

yum -y install epel-release
yum -y install ansible

できた。ansible2.9インストール完了
image.png

これがコントロールノードになる。

ターゲットノードへ疎通できるようにする

コントロールノードでsshキーペアを作成して、公開鍵をターゲットノード(nbfr000)へ保管してやろう

ssh-keygen

実行結果がこちら。
$HOME/.ssh/id_rsa.pubが公開鍵になる。
image.png

公開鍵をターゲットノード(nbfr000)へ保管してssh接続できるようにする。
やり方は単純で、id_rsa.pubの内容をcatで出力して、
ターゲットノードの$HOME/.ssh/authorized_keys の末尾に追記するだけ

これを・・・
image.png

こんな感じで追記してやる。超力業だけどさくっとやりたいのでこれでOK。
image.png

接続確認

コントロールノード(nbfr151v)からターゲットノード(nbfr000)へssh接続する。
ちなみにターゲットノード(nbfr000)のプライベートIPは10.0.0.9とする

ssh azureuser@10.0.0.9

こんな感じで接続成功
image.png

プレイブック作って動作確認

コントロールノード側でプレイブックを作って動かそう。

こんな構成で。ansible.cfgとhostsはデフォルトだと/etc/ansible/配下に同名のファイルがあってそちらを参照するけど
ansible-playbookを実行したときのカレントディレクトリ配下に同名のファイルがあればそれを優先するので
こっちに置くことにした。
~/playbook
|–ansible.cfg
|–hosts
|–test.yml

test.yml
- name: test
  hosts: test_servers
  remote_user: azureuser
  become: yes
  become_user: root
  tasks:
  - name: ping pong check
    ping:

image.png

実行したいときはコレ

ansible-playbook -i hosts test.yml

これで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?