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

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
59
Help us understand the problem. What is going on with this article?
@kiarina

Ansibleでsshユーザを指定する

More than 5 years have passed since last update.

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

参考

59
Help us understand the problem. What is going on with this article?
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

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
59
Help us understand the problem. What is going on with this article?