Help us understand the problem. What is going on with this article?

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

参考

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
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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