はじめに
状況
AnsibleでBastion(踏み台)経由でrsync(ansible.builtin.synchronize)を使用してファイルをデプロイしたいが、なぜかrsyncの段階でHost Key Verification Failedになってタスクが進行しなくなる。
やったこと
- ansible.cfg
- ssh_connection
-
ssh_args = -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/nullを入れる
-
- defaults
-
host_key_checking = Falseを入れる
-
- ssh_connection
- ansible_ssh_common_args
-
-JやProxyJumpなどの踏み台オプションを使用する
-
- ansible.builtin.synchronize
-
use_ssh_args: yesを入れる -
rsync_optsに各種sshオプションを追加する
-
しかし、いずれも効果なし
解決方法
all.yml
ansible_ssh_common_args: >-
-o ProxyCommand="ssh -i {{ ansible_ssh_private_key_file}} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null {{ bastion_username }}@{{ bastion_host }} -W %h:%p"
task.yml
- name: rsyncする
ansible.builtin.synchronize:
src: "{{ srcpath }}"
dest: "{{ destpath }}"
recursive: yes
compress: yes
use_ssh_args: yes
とすることで、ホスト鍵検証をrsyncでも無効化出来ました。
どうも-JやProxyJumpではrsyncまでオプションがちゃんと渡らないみたいです。