LoginSignup
3
2

More than 5 years have passed since last update.

ansible-playbookのremote_userの設定について

Last updated at Posted at 2016-11-29

TL;DR

  1. コピペはよくない
  2. ansibleがremote_userの設定を見に行く順番は
    1. playbook(site.yml)
    2. -u オプション
    3. 環境変数 ANSIBLE_CONFIG
    4. ansible.cfg
    5. ~/.ansible.cfg
    6. /etc/ansible/ansible.cfg

背景

playbookを作ってinventoryファイルに対象を書いてリモートサーバに対して実行しようとplaybookを流してみると

fatal: [10.XXX.XXX.XXX]: UNREACHABLE! => {
    "changed": false, 
    "msg": "Failed to connect to the host via ssh: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).\r\n", 
    "unreachable": true
}

な感じで怒られる。

ansible all -m ping -i hosts
10.XXX.XXX.XXX | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

はこんな感じでちゃんと成功する

ansible-playbook -i hosts -vvv -u hoge

みたいに書いても
カレントディレクトリにansible.cfg置いてremote_user=hogeを書いても
/etc/ansible/ansible.cfgremote_user=hogeを書いても反映されない
なんでだろうなって思ったら、どこかからコピペしてきたsite.ymlにremote_user=rootって書いてて
そりゃrootで実行されるわって思いました。

3
2
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
3
2