{"action":"created","issue":{"url":"https://api.github.com/repos/ansible/ansible/issues/9151","labels_url":"https://api.github.com/repos/ansible/ansible/issues/9151/labels{/name}","comments_url":"https://api.github.com/repos/ansible/ansible/issues/9151/comments","events_url":"https://api.github.com/repos/ansible/ansible/issues/9151/events","html_url":"https://github.com/ansible/ansible/pull/9151","id":43951413,"number":9151,"title":"Template delegate private key","user":{"login":"ahamilton55","id":936174,"avatar_url":"https://avatars.githubusercontent.com/u/936174?v=3","gravatar_id":"","url":"https://api.github.com/users/ahamilton55","html_url":"https://github.com/ahamilton55","followers_url":"https://api.github.com/users/ahamilton55/followers","following_url":"https://api.github.com/users/ahamilton55/following{/other_user}","gists_url":"https://api.github.com/users/ahamilton55/gists{/gist_id}","starred_url":"https://api.github.com/users/ahamilton55/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahamilton55/subscriptions","organizations_url":"https://api.github.com/users/ahamilton55/orgs","repos_url":"https://api.github.com/users/ahamilton55/repos","events_url":"https://api.github.com/users/ahamilton55/events{/privacy}","received_events_url":"https://api.github.com/users/ahamilton55/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ansible/ansible/labels/bugfix_pull_request","name":"bugfix_pull_request","color":"ded270"},{"url":"https://api.github.com/repos/ansible/ansible/labels/P3","name":"P3","color":"fef2c0"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-09-25T18:32:44Z","updated_at":"2015-07-25T05:58:56Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ansible/ansible/pulls/9151","html_url":"https://github.com/ansible/ansible/pull/9151","diff_url":"https://github.com/ansible/ansible/pull/9151.diff","patch_url":"https://github.com/ansible/ansible/pull/9151.patch"},"body":"##### Issue Type:\r\nBugfix Pull Requiest\r\n\r\n##### Ansible Version:\r\nansible 1.8 (devel 19703617b8) last updated 2014/09/25 10:53:31 (GMT -700)\r\n\r\n##### Environment:\r\nRunning from: Mac OS X 10.9, Fedora 20\r\nRunning against: Debian 7, Centos 6/7\r\n\r\n##### Summary:\r\nWhen using the \"local_action\" module or \"delegate_to\" with a private key filename that includes variables such as, \"~/.ssh/{{ key_name | default(group) }}.pem,\" Ansible will throw a OSError exception when looking up the key. `template.template()` is called on the private key filename when delegation is not used but not when it is.\r\n\r\nThe following line is used in `group_vars/all` for the private key filename:\r\n```ansible_ssh_private_key_file: ~/.ssh/{{ key_name | default(group) }}.pem```\r\n\r\nThe stacktrace given is the following:\r\n```\r\nfatal: [ip-10-X-Y-Z.<region>.compute -> 127.0.0.1] => Traceback (most recent call last):\r\n  File \"/Users/andrew/workspace/ansible/lib/ansible/runner/__init__.py\", line 563, in _executor\r\n    exec_rc = self._executor_internal(host, new_stdin)\r\n  File \"/Users/andrew/workspace/ansible/lib/ansible/runner/__init__.py\", line 713, in _executor_internal\r\n    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)\r\n  File \"/Users/andrew/workspace/ansible/lib/ansible/runner/__init__.py\", line 875, in _executor_internal_inner\r\n    conn = self.connector.connect(actual_host, actual_port, actual_user, actual_pass, actual_transport, actual_private_key_file)\r\n  File \"/Users/andrew/workspace/ansible/lib/ansible/runner/connection.py\", line 39, in connect\r\n    st = os.stat(private_key_file)\r\nOSError: [Errno 2] No such file or directory: '/Users/andrew/.ssh/{{ key_name | default(group) }}.pem'\r\n```\r\n\r\n##### Steps To Reproduce:\r\n1. Add `ansible_ssh_private_key_file` in a `group_vars` file such as `group_vars/all` and have it use a variable in the file path such as:\r\n```ansible_ssh_private_key_file: ~/.ssh/{{ service_name }}.pem\r\nservice_name: test```\r\n\r\n2. Make sure that the path is to an actual file and that the proper permissions are set (`chmod 0600 <path>`)\r\n\r\n3. Use \"local_action\" or delegate to with any module. For example, you can create a playbook such as `test.yml` with the following gist: https://gist.github.com/ahamilton55/d081087abaa6399b3487\r\n\r\n4. Run with something like `ansible-playbook -i hosts.yml test.yml`.\r\n\r\n##### Expected Results:\r\n```\r\n% ansible-playbook -i hosts.yml test.yml \r\n\r\nPLAY [test] ******************************************************************* \r\n\r\nTASK: [Pause for a bit] ******************************************************* \r\n(^C-c = continue early, ^C-a = abort)\r\n[testhost]\r\nPausing for 4 seconds\r\nok: [testhost -> 127.0.0.1]\r\n\r\nPLAY RECAP ******************************************************************** \r\ntesthost      : ok=1    changed=0    unreachable=0    failed=0\r\n```\r\n\r\n##### Actual Results:\r\n```\r\n% ansible-playbook -i hosts.yml\r\n\r\nPLAY [test] ******************************************************************* \r\n\r\nTASK: [Pause for a bit] ******************************************************* \r\nfatal: [testhost -> 127.0.0.1] => Traceback (most recent call last):\r\n  File \"/home/andrew/workspace/ansible/lib/ansible/runner/__init__.py\", line 563, in _executor\r\n    exec_rc = self._executor_internal(host, new_stdin)\r\n  File \"/home/andrew/workspace/ansible/lib/ansible/runner/__init__.py\", line 713, in _executor_internal\r\n    return self._executor_internal_inner(host, self.module_name, self.module_args, inject, port, complex_args=complex_args)\r\n  File \"/home/andrew/workspace/ansible/lib/ansible/runner/__init__.py\", line 875, in _executor_internal_inner\r\n    conn = self.connector.connect(actual_host, actual_port, actual_user, actual_pass, actual_transport, actual_private_key_file)\r\n  File \"/home/andrew/workspace/ansible/lib/ansible/runner/connection.py\", line 39, in connect\r\n    st = os.stat(private_key_file)\r\nOSError: [Errno 2] No such file or directory: '/home/andrew/.ssh/{{ service_name }}.pem'\r\n\r\n\r\nFATAL: all hosts have already failed -- aborting\r\n\r\nPLAY RECAP ******************************************************************** \r\n           to retry, use: --limit @/home/andrew/test.retry\r\n\r\ntesthost      : ok=0    changed=0    unreachable=0    failed=1\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/ansible/ansible/issues/comments/124805217","html_url":"https://github.com/ansible/ansible/pull/9151#issuecomment-124805217","issue_url":"https://api.github.com/repos/ansible/ansible/issues/9151","id":124805217,"user":{"login":"amenonsen","id":23628,"avatar_url":"https://avatars.githubusercontent.com/u/23628?v=3","gravatar_id":"","url":"https://api.github.com/users/amenonsen","html_url":"https://github.com/amenonsen","followers_url":"https://api.github.com/users/amenonsen/followers","following_url":"https://api.github.com/users/amenonsen/following{/other_user}","gists_url":"https://api.github.com/users/amenonsen/gists{/gist_id}","starred_url":"https://api.github.com/users/amenonsen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amenonsen/subscriptions","organizations_url":"https://api.github.com/users/amenonsen/orgs","repos_url":"https://api.github.com/users/amenonsen/repos","events_url":"https://api.github.com/users/amenonsen/events{/privacy}","received_events_url":"https://api.github.com/users/amenonsen/received_events","type":"User","site_admin":false},"created_at":"2015-07-25T05:58:56Z","updated_at":"2015-07-25T05:58:56Z","body":"This PR can be closed, the problem has already been fixed in devel. (I tested it.)"}}