1
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 5 years have passed since last update.

ansibleの勉強を初めてみた

Last updated at Posted at 2018-10-27

ansibleメモ

イベントリーファイル

  • 資材を配置するサーバを指定できる
  • []で括ることで、サーバグループを作成する可能
server1.sample.com
server2.sample.com

[mail]
server3.sample.com
server4.sample.com

[db]
server5.sample.com
server6.sample.com

web  ansible_host=server1.company.com ansible_connection=ssh   ansible_user=root
db   ansible_host=server2.company.com ansible_connection=winrm   ansible_user=admin
mail ansible_host=server3.company.com ansible_connection=ssh   ansible_ssh_pass=P@#
web2 ansible_host=server4.company.com ansible_connection=winrm

localhost ansible_connection=localhost

パラメータ例
ansible_connection - ssh/winrm/localhost
ansible_port - 22/5986
ansible_user - root/administrator
ansible_ssh_pass - Password
  • インベントリーファイル作成
[osboxes@osboxes test-project]$ cat inventory.txt
target1 ansible_host=192.168.11.30 ansible_ssh_pass=osboxes.org

[osboxes@osboxes test-project]$ ansible target1 -m ping -i inventory.txt
target1 | FAILED! => {
    "msg": "Using a SSH password instead of a key is not possible because Host Key checking is enabled and sshpass does not support this.  Please add this host's fingerprint to your known_hosts file to manage this host."
}

ssh接続をしたことないサーバに接続する場合には、上記のようなエラーが出るみたい
そのため、ansibleから接続する前に、一度sshコマンドでサーバに接続する

  • 便利メモ

サービスの起動もできる
serviceコマンド

テキストファイルの書き換えも可能
lineinfileコマンド

ドメインネームサーバへの追加
vars: dns_server

コマンドのループもできる
with_items:

  • ansible roles

include
vars_files:

  • variables.yml

tasks:

  • include: tasks.yml

playAbleでいろいろ確認できるみたい

力尽きたのであとで書き直そ

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?