Ansibleを試した件

Debian系(Ubuntu)で、

サーバー環境の中で、

処理等の管理で良い方法を探していて、

Ansibleを使っている方がいらっしゃるようなので、

自分の方でも試してみることにした。

今回は、

Ansibleを調べるところから、

試すまでを色々することになったので、

その際の個人的なメモ。

Ansibleとは

Ansibleについては、

簡潔にまとめると、

  • IT自動化ツール
  • エージェントレス(SSH接続)
  • YAML形式で構成管理
  • 冪等性(何度実行しても同じ結果)
  • モジュールベースで拡張可能

ということらしい。

簡潔にまとめると、

ということになるのかなと。

Ansibleの公式情報

実際に調べながら、

試してみるにあたって、

公式情報はどこなのかを調べてメモ。

Ansibleについて

公式情報で、個人的にメモしたいところ。

引用しながら、

これ、公式より引用。

Module code is executed locally on the control node.

モジュールコードはコントロールノード上でローカルに実行される

これは、

「Network Automation側」

のことなのかなと。

Module code is copied on the managed node, executed, then removed.

モジュールコードはマネージドノードにコピーされ、実行され、その後削除される

これは、

「Server Automation側」

のことなのかなと。

Ansibleはモジュールを

マネージドノード(対象サーバー)に送って、そこで実行して削除する。

ということなのかと。

参考:公式より引用

Ansibleを試す

MacにAnsibleを導入

コマンド

brew install ansible

inventoryファイルを作る

ファイル名

vim inventory.ini

内容サンプル

[sample]
your-ip ansible_user=root ansible_ssh_private_key_file=~/.ssh/id_rsa

Playbookを作る

ファイル名

vim playbook.yml

内容

- hosts: sample
  gather_facts: yes
  tasks:
    - name: Display hostname
      debug:
        msg: "The hostname is {{ ansible_hostname }}"

これで、

実行コマンド

ansible-playbook -i inventory.ini playbook.yml

を行うと、

PLAY [sample] ************************

TASK [Gathering Facts] ***************
[WARNING]: 
Platform linux on host your-ip is using 
the discovered Python interpreter
at /usr/bin/python3.8, 
but future installation 
of another Python interpreter could change
the meaning of that path. 
See https://docs.ansible.com/ansible-
core/2.18/reference_appendices/interpreter_discovery.html 
for more information.
ok: [your-ip]

TASK [Display hostname] ***************
ok: [your-ip] => {
    "msg": "The hostname is Sample-Hostname"
}

PLAY RECAP ****************************
your-ip :ok=2   

のような結果が出たので、

うまく挙動しました。

ピックアップ

こちらもおすすめ

初心者向けの色々な情報はあるけれど、

  • 無料でお試しができるスクール
  • ホームページなど簡単に作成できる
  • 組織で使いたいサービス

について、

少しでも試して良いものがあると、

それを活用することで学習や業務などが効率化できるので、

おすすめのサイトなどをいくつか紹介しておきます

おすすめ書籍

コメント一覧

コメントはまだありません。

コメント送信

コメントを残す

広告

おすすめ記事