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

[BUG] salt['cmd.run']("id -un") failed on Windows 10 #495

Closed
kartnico opened this issue Dec 29, 2020 · 9 comments
Closed

[BUG] salt['cmd.run']("id -un") failed on Windows 10 #495

kartnico opened this issue Dec 29, 2020 · 9 comments
Assignees

Comments

@kartnico
Copy link

kartnico commented Dec 29, 2020

Formula commit hash / release tag

commit a1b4887
Author: semantic-release-bot semantic-release-bot@martynus.net
Date: Wed Dec 23 18:54:47 2020 +0000

Versions reports (master & minion)

minion :

Salt Version:
          Salt: 3002.2

Dependency Versions:
          cffi: 1.12.2
      cherrypy: 17.4.1
      dateutil: 2.8.0
     docker-py: Not Installed
         gitdb: 2.0.5
     gitpython: Not Installed
        Jinja2: 2.10.1
       libgit2: Not Installed
      M2Crypto: Not Installed
          Mako: 1.0.7
       msgpack: 1.0.0
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: 2.19
      pycrypto: Not Installed
  pycryptodome: 3.9.8
        pygit2: Not Installed
        Python: 3.7.4 (tags/v3.7.4:e09359112e, Jul  8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)]
  python-gnupg: 0.4.4
        PyYAML: 5.3.1
         PyZMQ: 18.0.1
         smmap: 2.0.5
       timelib: 0.2.4
       Tornado: 4.5.3
           ZMQ: 4.3.1

System Versions:
          dist:
        locale: cp1252
       machine: AMD64
       release: 10
        system: Windows
       version: 10 10.0.19041 SP0

master :

Salt Version:
          Salt: 3002.2

Dependency Versions:
          cffi: Not Installed
      cherrypy: Not Installed
      dateutil: Not Installed
     docker-py: Not Installed
         gitdb: Not Installed
     gitpython: Not Installed
        Jinja2: 2.11.1
       libgit2: Not Installed
      M2Crypto: 0.35.2
          Mako: Not Installed
       msgpack: 0.6.2
  msgpack-pure: Not Installed
  mysql-python: Not Installed
     pycparser: Not Installed
      pycrypto: Not Installed
  pycryptodome: Not Installed
        pygit2: Not Installed
        Python: 3.6.8 (default, Nov 16 2020, 16:55:22)
  python-gnupg: Not Installed
        PyYAML: 3.13
         PyZMQ: 17.0.0
         smmap: Not Installed
       timelib: Not Installed
       Tornado: 4.5.3
           ZMQ: 4.1.4

System Versions:
          dist: centos 7 Core
        locale: UTF-8
       machine: x86_64
       release: 3.10.0-1160.6.1.el7.x86_64
        system: Linux
       version: CentOS Linux 7 Core

Pillar / config used

salt:
  clean_config_d_dir: False
  minion_remove_config: True
  master_remove_config: True
  py_ver: 'py3'
  install_packages: True
  pygit2: python3-pygit2

  lookup:
    salt-master: 'salt-master'
    salt-minion: 'salt-minion'
    salt-syndic: 'salt-syndic'
    salt-cloud: 'salt-cloud'
    salt-ssh: 'salt-ssh'

  minion:
    backup_mode: minion
    id: {{ grains['id']|lower }}
    schedule:
      - uptodate:
        - function: pkg.uptodate
        - kwargs:
          refresh: True
        - minutes: 1440

Bug details

Describe the bug

---
2020-12-29 07:34:52,754 [salt.state       :3973][CRITICAL][4268] Rendering SLS 'base:salt.minion' failed: Problem running salt function in Jinja template: Unable to run command 'id -un' with the context '{'cwd': 'C:\\Windows\\system32\\config\\systemprofile', 'shell': False, 'env': {'ALLUSERSPROFILE': 'C:\\ProgramData', 'APPDATA': 'C:\\Windows\\system32\\config\\systemprofile\\AppData\\Roaming', 'CommonProgramFiles': 'C:\\Program Files\\Common Files', 'CommonProgramFiles(x86)': 'C:\\Program Files (x86)\\Common Files', 'CommonProgramW6432': 'C:\\Program Files\\Common Files', 'COMPUTERNAME': 'VM-WINDOWS10-02', 'ComSpec': 'C:\\Windows\\system32\\cmd.exe', 'DriverData': 'C:\\Windows\\System32\\Drivers\\DriverData', 'LOCALAPPDATA': 'C:\\Windows\\system32\\config\\systemprofile\\AppData\\Local', 'NUMBER_OF_PROCESSORS': '2', 'OS': 'Windows_NT', 'Path': 'C:\\Windows\\system32;C:\\Windows;C:\\Windows\\System32\\Wbem;C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\;C:\\Windows\\System32\\OpenSSH\\;c:\\salt;C:\\Windows\\system32\\config\\systemprofile\\AppData\\Local\\Microsoft\\WindowsApps', 'PATHEXT': '.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC', 'PROCESSOR_ARCHITECTURE': 'AMD64', 'PROCESSOR_IDENTIFIER': 'Intel64 Family 6 Model 6 Stepping 3, GenuineIntel', 'PROCESSOR_LEVEL': '6', 'PROCESSOR_REVISION': '0603', 'ProgramData': 'C:\\ProgramData', 'ProgramFiles': 'C:\\Program Files', 'ProgramFiles(x86)': 'C:\\Program Files (x86)', 'ProgramW6432': 'C:\\Program Files', 'PSModulePath': 'C:\\Program Files\\WindowsPowerShell\\Modules;C:\\Windows\\system32\\WindowsPowerShell\\v1.0\\Modules', 'PUBLIC': 'C:\\Users\\Public', 'SystemDrive': 'C:', 'SystemRoot': 'C:\\Windows', 'TEMP': 'C:\\Windows\\TEMP', 'TMP': 'C:\\Windows\\TEMP', 'USERDOMAIN': 'WORKGROUP', 'USERNAME': 'VM-WINDOWS10-02$', 'USERPROFILE': 'C:\\Windows\\system32\\config\\systemprofile', 'windir': 'C:\\Windows'}, 'stdin': None, 'stdout': -1, 'stderr': -2, 'with_communicate': True, 'timeout': None, 'bg': False}', reason: [WinError 2] The system cannot find the file specified
c:\salt\var\cache\salt\minion\files\base\salt/osfamilymap.yaml(22):
---
[...]
#from template-formula
{%- if grains.os_family == 'MacOS' %}
{%-   set rootuser = salt['cmd.run']("stat -f '%Su' /dev/console") %}
{%-   set rootgroup = salt['cmd.run']("stat -f '%Sg' /dev/console") %}
{%- elif grains.os_family == 'Windows' %}
{%-   set rootuser = salt['cmd.run']("id -un") %}    <======================
{%- endif %}
@kartnico kartnico added the bug label Dec 29, 2020
@myii
Copy link
Member

myii commented Dec 29, 2020

Thanks for the report, @kartnico. As you can see under the Actions tab, we have Windows testing taking place, so I wonder why that's not tripping up on this. In fact, it's picking it up as kitchen:

From a quick look around, it appears that the whoami command should work.

https://ss64.com/nt/whoami.html

Equivalent bash command (Linux): whoami - Print the current user id and name (id -un).

Can you try that out and see if it works for you?

@kartnico
Copy link
Author

kartnico commented Dec 29, 2020

{%- set rootuser = salt['cmd.run']("whoami") %}

works on Windows 10.

myii added a commit to myii/salt-formula that referenced this issue Dec 29, 2020
@myii
Copy link
Member

myii commented Dec 29, 2020

Tested whoami in GitHub Actions but this causes a different value to be set:

Would need to figure out how to ensure the same value is extracted.

@kartnico
Copy link
Author

Could you try this ?

{%- set rootuser = salt['cmd.powershell']("(whoami).split('\')[1]") %}

It works also for me.

myii added a commit to myii/salt-formula that referenced this issue Dec 29, 2020
@myii
Copy link
Member

myii commented Dec 29, 2020

Could you try this ?

{%- set rootuser = salt['cmd.powershell']("(whoami).split('\')[1]") %}

It works also for me.

@kartnico Due to the nature of cmd.powershell, that ends up returning an empty dict (rootuser: {}). See the following for more info:

Tried various other combinations but finally found one that works properly:

{%-   set rootuser = salt['cmd.run']("whoami").split("\\")[1] %}

That's working on Vagrant (locally) as well as in GitHub Actions:

@kartnico
Copy link
Author

It also works for me. Thank you.

myii added a commit to myii/salt-formula that referenced this issue Jan 12, 2021
@dafyddj dafyddj closed this as completed Feb 25, 2021
@dafyddj
Copy link
Contributor

dafyddj commented Feb 25, 2021

Closed in error.

@dafyddj dafyddj reopened this Feb 25, 2021
@myii
Copy link
Member

myii commented Feb 25, 2021

Thanks for reopening, @dafyddj -- the fix still needs to be provided here, since it was only tested in my fork.

@myii myii self-assigned this Feb 25, 2021
myii added a commit to myii/salt-formula that referenced this issue Mar 12, 2021
@myii myii closed this as completed in 69d5981 Mar 30, 2021
saltstack-formulas-travis pushed a commit that referenced this issue Mar 30, 2021
## [1.8.1](v1.8.0...v1.8.1) (2021-03-30)

### Bug Fixes

* **freebsd:** update to provide support for most recent versions ([24ebbb4](24ebbb4))
* **openbsd:** update to provide support for most recent versions ([61201de](61201de))
* **osfamilymap:** use `whoami` for Windows `rootuser` ([69d5981](69d5981)), closes [#495](#495)

### Code Refactoring

* **retry_options:** provide options from defaults/pillar ([bbd7286](bbd7286))

### Continuous Integration

* enable Vagrant-based testing using GitHub Actions ([163c77f](163c77f))
* **kitchen+ci:** use latest pre-salted images (after CVE) [skip ci] ([cfefcc8](cfefcc8))
* **windows:** use `kitchen.windows.yml` ([c6043fb](c6043fb))

### Documentation

* **readme:** add `Testing with Vagrant` section ([ef1bc02](ef1bc02))

### Tests

* update for new platforms (inc. using `system` library) ([e6bcdc1](e6bcdc1))
* **_mapdata:** add Arch Linux verification file ([e31a56e](e31a56e))
* add Windows map verification files ([e0afe89](e0afe89))
* standardise use of `share` suite & `_mapdata` state [skip ci] ([9816f47](9816f47))
@saltstack-formulas-travis

🎉 This issue has been resolved in version 1.8.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants