65
61

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でsshユーザを指定する

Last updated at Posted at 2014-10-06

sshユーザを指定してansibleを実行する

  • インベントリファイルでsshユーザを指定する
  • ansible-playbook 実行時にオプション -k -c paramiko してパスワードを入力する

設定ファイル

hosts
[web]
192.168.43.52

[db]
192.168.43.53

[all:vars]
ansible_ssh_user=vagrant
ansible.cfg
[defaults]
hostfile = ./hosts
playbook.yml
---
- hosts: all
  sudo: yes
  vars:
    password: ****
  tasks:
    - name: add a new user
      user: name=hoge password={{password}} state=present

実行

ansible-playbook playbook.yml -k -c paramiko

TIPS

ssh関連の設定

hosts
[webservers]
192.168.43.52

[all:vars]
ansible_ssh_port=22
ansible_ssh_user=ansible
ansible_ssh_pass=p@ssW0rd
ansible_sudo_pass=p@ssW0rd

インベントリファイルでの指定方法

hosts
[web]
192.168.43.52 ansible_ssh_user=vagrant

[db]
192.168.43.53

[db:vars]
ansible_ssh_user=vagrant

[all:vars]
ansible_ssh_user=vagrant

参考

65
61
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
65
61

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?