jborean93 / ansible-role-win_openssh

Ansible Role to install Win32-OpenSSH on Windows - https://github.com/PowerShell/Win32-OpenSSH
MIT License
28 stars 17 forks source link

Repeated Commands in master #16

Closed jimbo8098 closed 3 years ago

jimbo8098 commented 3 years ago

I've noted the following in the most recent version of the role:

TASK [jborean93.win_openssh : get the localised name for the Administrators group] **************************************************************************
task path: /home/jimspeir/.ansible/roles/jborean93.win_openssh/tasks/sshd_config.yml:36
redirecting (type: modules) ansible.builtin.win_shell to ansible.windows.win_shell
Using module file /home/jimspeir/.ansible/collections/ansible_collections/ansible/windows/plugins/modules/win_shell.ps1
Pipelining is enabled.
<127.0.0.1> ESTABLISH PSRP CONNECTION FOR USER: vagrant ON PORT 29500 TO 127.0.0.1
PSRP: EXEC (via pipeline wrapper)
fatal: [win-2019]: FAILED! => changed=false
  cmd: |-
    $sid = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList "S-1-5-32-544"
    ($sid.Translate([System.Security.Principal.NTAccount]).Value -split "\\$sid = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList "S-1-5-32-544"
    ($sid.Translate([System.Security.Principal.NTAccount]).Value -split "\\")[1]
  delta: '0:00:01.123056'
  end: '2021-09-02 09:31:37.429836'
  msg: non-zero return code
  rc: 1
  start: '2021-09-02 09:31:36.306779'
  stderr: |-
    The string is missing the terminator: ".
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
  stderr_lines: <omitted>
  stdout: ''
  stdout_lines: <omitted>

This occurs in:

jimspeir@saglv-dvlci-02:~/Projects/windows2019core$ ansible --version
ansible [core 2.11.4]
  config file = /home/jimspeir/Projects/windows2019core/ansible.cfg
  configured module search path = ['/home/jimspeir/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/jimspeir/.local/lib/python3.8/site-packages/ansible
  ansible collection location = /home/jimspeir/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/jimspeir/.local/bin/ansible
  python version = 3.8.10 (default, Jun  2 2021, 10:49:15) [GCC 9.4.0]
  jinja version = 2.10.1
  libyaml = True

I was able to fix the issue where the command ends abruptly using the following:

- name: get the localised name for the Administrators group
  win_shell: !unsafe |
    $sid = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList "S-1-5-32-544"
    ($sid.Translate([System.Security.Principal.NTAccount]).Value -split {% raw %}"{{ '\\' }}"{% endraw %})[1]
  register: pri_openssh_admin_name_raw
  check_mode: no
  changed_when: False

But this only ends in a similar situation:

TASK [jborean93.win_openssh : get the localised name for the Administrators group] ******************************************************************************************************************************************************************************************************************************************
fatal: [win-2019]: FAILED! => changed=false
  cmd: |-
    $sid = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList "S-1-5-32-544"
    ($sid.Translate([System.Security.Principal.NTAccount]).Value -split "\\$sid = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList "S-1-5-32-544"
    ($sid.Translate([System.Security.Principal.NTAccount]).Value -split "\\")[1]
  delta: '0:00:00.906197'
  end: '2021-09-03 05:03:13.819624'
  msg: non-zero return code
  rc: 1
  start: '2021-09-03 05:03:12.913426'
  stderr: |-
    The string is missing the terminator: ".
        + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
        + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString
  stderr_lines: <omitted>
  stdout: ''
  stdout_lines: <omitted>

I will keep having a look into this though since I'm building a Win 2019 Core VM using your windoze repo. Given the time, likely continuing on Monday.

jimbo8098 commented 3 years ago

Yeah something about this line isn't playing with Ansible:

($sid.Translate([System.Security.Principal.NTAccount]).Value -split "{{ '\\' }}")[1]

When this is added to the command, it immediately causes the command to repeat. If I run the same with just the first line it runs as expected:

 $sid = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList "S-1-5-32-544"
jimbo8098 commented 3 years ago

Ah think this may be it. If you use the following:

- win_shell: |
    $sid = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList "S-1-5-32-544"
    ($sid.Translate([System.Security.Principal.NTAccount]).Value -split '\\')
  check_mode: no
  changed_when: False

You get this output:

TASK [jborean93.win_openssh : configure sshd_config file] *******************************************************************************************************************************************************************************************************************************************************************
task path: /home/jimspeir/.ansible/roles/jborean93.win_openssh/tasks/service.yml:27
redirecting (type: modules) ansible.builtin.win_lineinfile to community.windows.win_lineinfile
redirecting (type: modules) ansible.builtin.win_lineinfile to community.windows.win_lineinfile
redirecting (type: modules) ansible.builtin.win_lineinfile to community.windows.win_lineinfile
redirecting (type: modules) ansible.builtin.win_lineinfile to community.windows.win_lineinfile
fatal: [windoze]: FAILED! =>
  reason: |-
    failed at splitting arguments, either an unbalanced jinja2 block or quotes: $sid = New-Object -TypeName System.Security.Principal.SecurityIdentifier -ArgumentList "S-1-5-32-544"
    ($sid.Translate([System.Security.Principal.NTAccount]).Value -split '\\')

    The error appears to be in '/home/jimspeir/.ansible/roles/jborean93.win_openssh/tasks/sshd_config.yml': line 36, column 3, but may
    be elsewhere in the file depending on the exact syntax problem.

    The offending line appears to be:

    - win_shell: |
      ^ here

How weird!

jimbo8098 commented 3 years ago

Looks like I've fixed it, will clean up and PR