さわらブログ

さわら(@xhiroga)の技術ブログ

Ansibleでbecomeを有効にすると、Escalation succeededと表示されるが処理が進まない → sudoのパスワードかユーザーが誤っているか、ControlMasterを有効化で解決

TL;DR

  • Ansibleはsudoのユーザーとして、デフォルトで root を使用する。変更したい場合は ansible_become_user オプションを指定すること
  • ssh_args = -F ssh_config を有効化している場合、同時に -C -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=~/.ansible/cp/ansible-ssh-%h-%p-%r も設定しないとsudo時のパスワードの受け渡しが失敗するようだ

Detail

実際のエラーです。Escalation succeeded というのも紛らわしいですよね...

Escalation succeeded
  5416 1637070979.58389: stderr chunk (state=3):
>>>debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: PTY allocation request accepted on channel 0
debug2: channel 0: rcvd adjust 2097152
debug3: receive packet: type 99
<<<
  5416 1637070979.58397: stderr chunk (state=3):
>>>debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
<<<
  5416 1637070979.58965: stdout chunk (state=3):
>>>[sudo via ansible, key=knnjbjweeaqhattpcizhggtvpermhceb] password:<<<

修正後の ansible.cfg の抜粋です。

[ssh_connection]
ssh_args = -F ssh_config -C -o ControlMaster=auto -o ControlPersist=60s -o ControlPath=~/.ansible/cp/ansible-ssh-%h-%p-%r

Reference

別の問題ですが、ssh_args 指定時のオプションに着目していたのでヒントになりました。

serverfault.com