Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

synchronize doesn't substitute variables properly #16347

Closed
ovcharenko opened this issue Jun 17, 2016 · 1 comment · Fixed by #16349
Closed

synchronize doesn't substitute variables properly #16347

ovcharenko opened this issue Jun 17, 2016 · 1 comment · Fixed by #16349
Labels
bug This issue/PR relates to a bug.

Comments

@ovcharenko
Copy link
Contributor

ISSUE TYPE
  • Bug Report
ANSIBLE VERSION
ansible 2.1.0.0
  config file = /tmp/ansible.cfg
  configured module search path = Default w/o overrides
CONFIGURATION
[defaults]

hostfile = ./hostfile

remote_tmp = /tmp

forks=10

timeout = 60

[paramiko_connection]

pty=False

[ssh_connection]

scp_if_ssh = True
control_path = %(directory)s/%%h-%%r
OS / ENVIRONMENT

N/A

SUMMARY
STEPS TO REPRODUCE

$cat hostfile

[test]
XXX.compute-1.amazonaws.com

$ cat test.yaml


---
- name: SSH test
  hosts: all
  tasks:
   - local_action: ping
   - synchronize: src=test.yaml dest=/tmp/

$ cat group_vars/all

credentials_base_dir: "{{ user_home }}/.ssh"
ec2_keypair: test

$ cat group_vars/test

aws_credential: test
ansible_ssh_private_key_file: "{{ credentials_base_dir }}/{{ aws_credential }}/{{ ec2_keypair }}.pem"

$ ansible-playbook test.yaml

EXPECTED RESULTS

All tasks will be completed.

ACTUAL RESULTS

synchronize task fails with unable to resolve ansible_ssh_private_key_file variable:

PLAY [SSH test] ****************************************************************

TASK [setup] *******************************************************************
ok: [XXX.compute-1.amazonaws.com]

TASK [ping] ********************************************************************
ok: [XXX.compute-1.amazonaws.com -> localhost]

TASK [synchronize] *************************************************************
fatal: [XXX.compute-1.amazonaws.com]: FAILED! => {"changed": false, "cmd": "/opt/local/bin/rsync --delay-updates -F --compress --archive --rsh 'ssh -i {{ credentials_base_dir }}/{{ aws_credential }}/{{ ec2_keypair }}.pem -S none -o StrictHostKeyChecking=no' --out-format='<<CHANGED>>%i %n%L' \"/tmp/test.yaml\" \"root@XXX.compute-1.amazonaws.com:/tmp/\"", "failed": true, "msg": "Warning: Identity file {{ not accessible: No such file or directory.\nssh: Could not resolve hostname credentials_base_dir: nodename nor servname provided, or not known\r\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: unexplained error (code 255) at io.c(226) [sender=3.1.1]\n", "rc": 255}

NO MORE HOSTS LEFT *************************************************************
    to retry, use: --limit @test.retry

PLAY RECAP *********************************************************************
XXX.compute-1.amazonaws.com : ok=2    changed=0    unreachable=0    failed=1
@ovcharenko
Copy link
Contributor Author

Ok... fix was really easy:

--- ansible/plugins/action/synchronize.py.orig  2016-06-17 20:25:19.000000000 +0300
+++ ansible/plugins/action/synchronize.py   2016-06-17 20:42:15.000000000 +0300
@@ -259,13 +259,10 @@
         dest = self._task.args.get('dest', None)
         if not dest_is_local:
             # Private key handling
-            if use_delegate:
-                private_key = task_vars.get('ansible_ssh_private_key_file') or self._play_context.private_key_file
-            else:
-                private_key = task_vars.get('ansible_ssh_private_key_file') or self._play_context.private_key_file
+            private_key = self._play_context.private_key_file

             if private_key is not None:
-                private_key = os.path.expanduser(private_key)
+                private_key = format(os.path.expanduser(private_key))
                 self._task.args['private_key'] = private_key

             # Src and dest rsync "path" handling

Please review and commit if appropriate.

abadger pushed a commit that referenced this issue Aug 4, 2016
… (#16349)

* Fix for issue @synchronize doesn't substitute variables properly #16347
abadger pushed a commit that referenced this issue Aug 4, 2016
… (#16349)

* Fix for issue @synchronize doesn't substitute variables properly #16347
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 7, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants