Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible synchronize asking for a password

I am using Ansible (1.9.2) to deploy some files to a Redhat 6.4 server.

The playbook looks something like this

- name: deploy files
  hosts: web
  tasks:
    - name sync files
      sudo: no
      synchronize:
        src={{ local_path }}
        dest={{ dest_path }}

And to kick this off I run something like the following

ansible-playbook -i myinventory myplaybook.yml -u DOMAIN\\user --ask-pass

When I start the play I enter my password at the prompt, facts are then obtained successfully, however as soon as the synchronize task is reached another prompt asks for my password again, like the following

DOMAIN\user@hostname's password:

If I enter my password again the deploy completes correctly.

My questions are

  1. How can I fix or work around this, so that I do not have to enter my password for every use of the synchronize module?
  2. Is this currently expected behaviour for the synchronize module? Or is this a bug in Ansible?

I cannot use ssh keys due to environment restrictions.

I do not want to use the copy module for scalability reasons.

Things I have tried

  1. I have seen a number of other questions on this subject but I have not been able to use any of them to fix my issue or understand if this is expected behavior.
    • Ansible synchronize prompts passphrase even if already entered at the beginning
    • Ansible prompts password when using synchronize
    • https://github.com/ansible/ansible/issues/5934
    • https://github.com/ansible/ansible/issues/7071
  2. The Ansible docs are generally excellent but I have not been able to find anything about this on the offical docs.
  3. I have tried specifiying the user and password in the inventory file and not using the --ask-pass and -u parameters. But while I then do not have to enter the password to collect facts, the synchronize module still requests my password.
  4. I have tried setting the --ask-sudo-pass as well, but it did not help
  5. I have been using a CentOS 7 control box, but I have also tried an Ubuntu 14.04 box

Can anyone help?

like image 628
pete.c Avatar asked Jan 30 '26 09:01

pete.c


1 Answers

To pass a password to synchronize module you can use --password-file option like so.

tasks:
- name: test_rsync
  synchronize:
    mode: pull
    src: rsync://user@host/your/remote/path
    dest: /your/local/path/
    rsync_opts:
      - "--password-file=/path/to/password_file"
like image 190
Олег Иванов Avatar answered Feb 02 '26 01:02

Олег Иванов



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!