Ansible not escaping windows path first argument

后端 未结 1 456
花落未央
花落未央 2021-01-24 10:23

I have playbook with windows path name in the extra arguments. first argument not escaping the drive letter and slash.

ansible-playbook d.yaml  --extra-vars \"ai         


        
相关标签:
1条回答
  • 2021-01-24 10:43

    installdir prints as c:\test, I expect it should print as c:\\test

    installdir contains: c : tab e s t.

    tab is replaced with \t in the debug module output and in effect you see c:\test on the screen.

    Other characters starting with backslash in your example (\p, \o, \l) do not have special meaning, so they are treated as two character strings; but you'd observe the same phenomenon with \n (and other escape sequences).


    1. Don't use debug module to debug things concerned with data, it processes strings to make them printable.

      Instead, use copy with content parameter and check the output in a file:

      - copy:
          content: |-
            installdir={{ installdir }}
            stragedir={{ stagedir }}
            outdir={{ outdir }}
          dest: ./result.txt
      

      (remember you could/should use hexdump to verify what's really inside).

    2. Use:

      ansible-playbook d.yaml --extra-vars "ainstalldir=c:\\\test stagedir=D:\\\packages outdir=d:\\\output\\\log"
      

      or

      ansible-playbook d.yaml --extra-vars 'ainstalldir=c:\\test stagedir=D:\\packages outdir=d:\\output\\log'
      

      Backslashes in double- and single quotes are interpreted differently by shell (see for example this question).

    0 讨论(0)
提交回复
热议问题