Ansible synchronize prompts passphrase even if already entered at the beginning

后端 未结 5 1918
青春惊慌失措
青春惊慌失措 2021-02-06 06:28

The synchronize module of Ansible (v1.6.5) prompts for the passphrase (Enter passphrase for key) even though I already entered it at the beginning of running th

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 07:18

    The synchronize command (up to at least Ansible 1.6.6) seems to ignore the normal SSH control socket opened by Ansible. Your task could expand to the following:

    {
        "cmd": "rsync --delay-updates -FF --compress --archive
            --rsh 'ssh  -o StrictHostKeyChecking=no'
            --out-format='<>%i %n%L'
            /home/me/src/ user@host:/dest/",
        "failed": true,
        "rc": 23
    }
    

    To get these details, run your playbook with the -v option. As a workaround for this, you can start ssh-agent and add cache your SSH key with ssh-add. Refer to their manual pages for details.

    Extra caveats with the synchronize module:

    • When run with sudo: yes, ansible will run with --rsh 'sudo ssh' which will break if the remote sudo configuration requires a password and/ or TTY. Solution: set sudo: no in your task definition.
    • The user that logs into the remote machine is your SSH user (ansible_ssh_user), not the sudo user. I have not found a way to override this user (besides an untested method that overrides the user with -o User option via one of the other options (dest_port="22 -o User=your_user"?) in combination with set_remote_user=yes).

    This is taken from my tasks file:

    - name: sync app files
      sudo: no
      synchronize: src={{app_srcdir}}/ dest={{appdir}}/
                   recursive=yes
                   rsync_opts=--exclude=.hg
    # and of course Ubuntu 12.04 does not support --usermap..
    #,--chown={{deployuser}}:www-data
    # the above goes bad because ansible_ssh_user=user has no privileges
    #  local_action: command rsync -av --chown=:www-data
    #                 {{app_srcdir}}
    #                 {{deployuser}}@{{inventory_hostname}}:{{appdir}}/
    #  when: app_srcdir is defined
    # The above still goes bad because {{inventory_hostname}} is not ssh host...
    

提交回复
热议问题