Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

More than 1 year has passed since last update.

@gogogonkun

ansibleの勉強を初めてみた

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でいろいろ確認できるみたい

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?