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

win_template: src is file dest is directory with and without ending slash #39886

Closed
jborean93 opened this issue May 9, 2018 · 4 comments · Fixed by #39887
Closed

win_template: src is file dest is directory with and without ending slash #39886

jborean93 opened this issue May 9, 2018 · 4 comments · Fixed by #39887
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. windows Windows community

Comments

@jborean93
Copy link
Contributor

jborean93 commented May 9, 2018

ISSUE TYPE
  • Bug Report
COMPONENT NAME

win_template

ANSIBLE VERSION
2.4
2.5
devel
CONFIGURATION

N/A

OS / ENVIRONMENT

Windows

SUMMARY

When using win_template to template a file to a destination that is a directory, it will either fail or create a file names source in the dest directory.

STEPS TO REPRODUCE

See https://github.com/jborean93/github-misc/tree/master/ansible/win_template-dest-dir-39886 for 2 different playbooks that shows this behaviour

EXPECTED RESULTS

In both cases, the 1st task would copy the template to C:\temp\template.txt and the 2nd task would result in no change.

When dest is a directory with the trailing \

TASK [template to directory with trailing slash] *****************************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/slash.yml:13
changed: [SERVER2016.domain.local] => {"changed": true, "checksum": "34d4150adc3347f1dd8ce19fdf65b74d971ab602"}

TASK [list files in directory] ***********************************************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/slash.yml:18
changed: [SERVER2016.domain.local] => {"changed": true, "cmd": "gci C:\\win_template-issue", "delta": "0:00:00.607388", "end": "2018-05-09 04:28:32.199792", "rc": 0, "start": "2018-05-09 04:28:31.592404", "stderr": "", "stderr_lines": [], "stdout": "\r\n\r\n    Directory: C:\\win_template-issue\r\n\r\n\r\nMode                LastWriteTime         Length Name                                                                  \r\n----                -------------         ------ ----                                                                  \r\n-a----         5/9/2018   2:28 PM              5 template.txt                                                          \r\n\r\n\r\n", "stdout_lines": ["", "", "    Directory: C:\\win_template-issue", "", "", "Mode                LastWriteTime         Length Name                                                                  ", "----                -------------         ------ ----                                                                  ", "-a----         5/9/2018   2:28 PM              5 template.txt                                                          ", "", ""]}

TASK [template to directory with trailing slash again] ***********************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/slash.yml:21
ok: [SERVER2016.domain.local] => {"changed": false, "checksum": "34d4150adc3347f1dd8ce19fdf65b74d971ab602"}

TASK [list files in directory] ***********************************************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/slash.yml:26
changed: [SERVER2016.domain.local] => {"changed": true, "cmd": "gci C:\\win_template-issue", "delta": "0:00:00.623016", "end": "2018-05-09 04:28:38.025042", "rc": 0, "start": "2018-05-09 04:28:37.402026", "stderr": "", "stderr_lines": [], "stdout": "\r\n\r\n    Directory: C:\\win_template-issue\r\n\r\n\r\nMode                LastWriteTime         Length Name                                                                  \r\n----                -------------         ------ ----                                                                  \r\n-a----         5/9/2018   2:28 PM              5 template.txt                                                          \r\n\r\n\r\n", "stdout_lines": ["", "", "    Directory: C:\\win_template-issue", "", "", "Mode                LastWriteTime         Length Name                                                                  ", "----                -------------         ------ ----                                                                  ", "-a----         5/9/2018   2:28 PM              5 template.txt                                                          ", "", ""]}
META: ran handlers
META: ran handlers

PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************************
SERVER2016.domain.local    : ok=5    changed=4    unreachable=0    failed=0   

When dest is a directory without the trailing \

TASK [template to directory without trailing slash] **************************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/no_slash.yml:13
changed: [SERVER2016.domain.local] => {"changed": true, "checksum": "34d4150adc3347f1dd8ce19fdf65b74d971ab602"}

TASK [list files in directory] ***********************************************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/no_slash.yml:18
changed: [SERVER2016.domain.local] => {"changed": true, "cmd": "gci C:\\win_template-issue", "delta": "0:00:00.605481", "end": "2018-05-09 04:27:19.948762", "rc": 0, "start": "2018-05-09 04:27:19.343281", "stderr": "", "stderr_lines": [], "stdout": "\r\n\r\n    Directory: C:\\win_template-issue\r\n\r\n\r\nMode                LastWriteTime         Length Name                                                                  \r\n----                -------------         ------ ----                                                                  \r\n-a----         5/9/2018   2:27 PM              5 template.txt                                                          \r\n\r\n\r\n", "stdout_lines": ["", "", "    Directory: C:\\win_template-issue", "", "", "Mode                LastWriteTime         Length Name                                                                  ", "----                -------------         ------ ----                                                                  ", "-a----         5/9/2018   2:27 PM              5 template.txt                                                          ", "", ""]}

TASK [template to directory without trailing slash again] ********************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/no_slash.yml:21
ok: [SERVER2016.domain.local] => {"changed": false, "checksum": "34d4150adc3347f1dd8ce19fdf65b74d971ab602"}

TASK [list files in directory] ***********************************************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/no_slash.yml:26
changed: [SERVER2016.domain.local] => {"changed": true, "cmd": "gci C:\\win_template-issue", "delta": "0:00:00.626031", "end": "2018-05-09 04:27:26.969417", "rc": 0, "start": "2018-05-09 04:27:26.343385", "stderr": "", "stderr_lines": [], "stdout": "\r\n\r\n    Directory: C:\\win_template-issue\r\n\r\n\r\nMode                LastWriteTime         Length Name                                                                  \r\n----                -------------         ------ ----                                                                  \r\n-a----         5/9/2018   2:27 PM              5 template.txt                                                          \r\n\r\n\r\n", "stdout_lines": ["", "", "    Directory: C:\\win_template-issue", "", "", "Mode                LastWriteTime         Length Name                                                                  ", "----                -------------         ------ ----                                                                  ", "-a----         5/9/2018   2:27 PM              5 template.txt                                                          ", "", ""]}
META: ran handlers
META: ran handlers

PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************************
SERVER2016.domain.local    : ok=5    changed=4    unreachable=0    failed=0   
ACTUAL RESULTS

When dest is a directory with the trailing \

  • On the 1st run works as expected, the file is copied to the dir with the same name as src
  • On the 2nd run it will fail saying the path is not a file
TASK [template to directory with trailing slash] *****************************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/slash.yml:13
changed: [SERVER2016.domain.local] => {"changed": true, "checksum": "34d4150adc3347f1dd8ce19fdf65b74d971ab602"}

TASK [list files in directory] ***********************************************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/slash.yml:18
changed: [SERVER2016.domain.local] => {"changed": true, "cmd": "gci C:\\win_template-issue", "delta": "0:00:00.601593", "end": "2018-05-09 04:30:57.631867", "rc": 0, "start": "2018-05-09 04:30:57.030274", "stderr": "", "stderr_lines": [], "stdout": "\r\n\r\n    Directory: C:\\win_template-issue\r\n\r\n\r\nMode                LastWriteTime         Length Name                                                                  \r\n----                -------------         ------ ----                                                                  \r\n-a----         5/9/2018   2:30 PM              5 template.txt                                                          \r\n\r\n\r\n", "stdout_lines": ["", "", "    Directory: C:\\win_template-issue", "", "", "Mode                LastWriteTime         Length Name                                                                  ", "----                -------------         ------ ----                                                                  ", "-a----         5/9/2018   2:30 PM              5 template.txt                                                          ", "", ""]}

TASK [template to directory with trailing slash again] ***********************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/slash.yml:21
fatal: [SERVER2016.domain.local]: FAILED! => {"changed": false, "checksum": "34d4150adc3347f1dd8ce19fdf65b74d971ab602", "msg": "path C:\\win_template-issue\\ is not a file"}
        to retry, use: --limit @/Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/slash.retry

PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************************
SERVER2016.domain.local    : ok=3    changed=3    unreachable=0    failed=1 

When dest is a directory without the trailing \

  • Both runs will result in a file called source in the directory specified by dest and will always show as a change
TASK [template to directory without trailing slash] **************************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/no_slash.yml:13
changed: [SERVER2016.domain.local] => {"changed": true, "checksum": "34d4150adc3347f1dd8ce19fdf65b74d971ab602"}

TASK [list files in directory] ***********************************************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/no_slash.yml:18
changed: [SERVER2016.domain.local] => {"changed": true, "cmd": "gci C:\\win_template-issue", "delta": "0:00:00.605063", "end": "2018-05-09 04:29:42.950212", "rc": 0, "start": "2018-05-09 04:29:42.345148", "stderr": "", "stderr_lines": [], "stdout": "\r\n\r\n    Directory: C:\\win_template-issue\r\n\r\n\r\nMode                LastWriteTime         Length Name                                                                  \r\n----                -------------         ------ ----                                                                  \r\n-a----         5/9/2018   2:29 PM              5 source                                                                \r\n\r\n\r\n", "stdout_lines": ["", "", "    Directory: C:\\win_template-issue", "", "", "Mode                LastWriteTime         Length Name                                                                  ", "----                -------------         ------ ----                                                                  ", "-a----         5/9/2018   2:29 PM              5 source                                                                ", "", ""]}

TASK [template to directory without trailing slash again] ********************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/no_slash.yml:21
changed: [SERVER2016.domain.local] => {"changed": true, "checksum": "34d4150adc3347f1dd8ce19fdf65b74d971ab602"}

TASK [list files in directory] ***********************************************************************************************************************************************************************************************************************************************************
task path: /Users/jborean/dev/github-misc/ansible/win_template-dest-dir-39886/no_slash.yml:26
changed: [SERVER2016.domain.local] => {"changed": true, "cmd": "gci C:\\win_template-issue", "delta": "0:00:00.587894", "end": "2018-05-09 04:29:49.992206", "rc": 0, "start": "2018-05-09 04:29:49.404311", "stderr": "", "stderr_lines": [], "stdout": "\r\n\r\n    Directory: C:\\win_template-issue\r\n\r\n\r\nMode                LastWriteTime         Length Name                                                                  \r\n----                -------------         ------ ----                                                                  \r\n-a----         5/9/2018   2:29 PM              5 source                                                                \r\n\r\n\r\n", "stdout_lines": ["", "", "    Directory: C:\\win_template-issue", "", "", "Mode                LastWriteTime         Length Name                                                                  ", "----                -------------         ------ ----                                                                  ", "-a----         5/9/2018   2:29 PM              5 source                                                                ", "", ""]}
META: ran handlers
META: ran handlers

PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************************
SERVER2016.domain.local    : ok=5    changed=5    unreachable=0    failed=0  
@ansibot
Copy link
Contributor

ansibot commented May 9, 2018

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented May 9, 2018

@ansibot ansibot added affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. support:core This issue/PR relates to code supported by the Ansible Engineering Team. windows Windows community labels May 9, 2018
jborean93 added a commit to jborean93/github-misc that referenced this issue May 9, 2018
@jhawkesworth
Copy link
Contributor

Good catch.
I prefer playbooks to be specific so to me its a syntax error not to specify a destination file. It is probably easier, and more intuitive for users, to infer the file name from the src than enforce that destination is a file though.

@jborean93
Copy link
Contributor Author

@jhawkesworth I'm the same which is why I never came across it before, I was creating a Windows vs linux comparison which used this format and is how I found out that it is broken.

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label May 9, 2018
@ansible ansible locked and limited conversation to collaborators May 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.6 This issue/PR affects Ansible v2.6 bug This issue/PR relates to a bug. module This issue/PR relates to a module. support:core This issue/PR relates to code supported by the Ansible Engineering Team. windows Windows community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants