The powershell shell family is incompatible with the sudo become plugin

I’m new with ansible projects.
when running this command :

ansible-playbook install_nginx.yml --ask-become-pass

I got this error :
TASK [Gathering Facts] *************************************************************************************************
fatal: [mem1]: FAILED! => {“msg”: “The powershell shell family is incompatible with the sudo become plugin”}
ok: [dc1]

my playbook as below :
template_nginx.yml :

---
- name: Install Nginx
  hosts: all
  become: true
#  become_method: winrm

  tasks:
    - name: Install Nginx
      apt:
        name: nginx
        state: present
      become: yes
      become_method: runas

    - name: Start Nginx
      service:
        name: nginx
        state: started

my inventory.ini :

my remote IP address

Are you trying to install Nginx on a Windows machine or an Ubuntu/Debian machine? You’ve got a bunch of mixed terms going on.

For Linux, the following should work on most distributions, not just Ubuntu/Debian.

---
- name: Install Nginx - Linux
  hosts: all
  become: true
  # become_method: sudo ## this is the default become_method

  tasks:
    - name: Install Nginx
      ansible.builtin.package: # Linux package manager agnostic
        name: nginx
        state: present

    - name: Start Nginx
      ansible.builtin.service:
        name: nginx
        state: started
        enabled: true

For Windows:
I’m just showing you what you might for Windows use since apt is a Debian package manager, not a Windows one. Not everyone is comfortable with using third party packagers for Windows, so you might need to download the Windows build, and configure everything (including a service) yourself.

---
- name: Install Nginx - Windows
  hosts: all
  become: true
  become_method: runas

  tasks:
    - name: Install Nginx
      chocolatey.chocolatey.win_chocolatey:
        name: nginx
        state: present

    - name: Start Nginx
      ansible.windows.win_service:
        name: nginx
        state: started
        state_mode: auto
2 Likes

thanks for your response, now dealing with the script for installign nginx I got this problem :

TASK [Start Nginx] *****************************************************************************************************
fatal: [10.241.200.114]: FAILED! => {“changed”: false, “msg”: “Service is in unknown state”, “status”: {}}

I’m using the Ubuntu distribtuion WSL on windows

Oh, WSL. Can you run wsl -l -v so we can see what version you’re running?

1 Like

As I think @Denney-tech is getting at, if you have WSL v1 this will not work without a lot of extra work inside WSL.

Here’s a good Services on WSL discussion on Stack Overflow.

Essential, for this to work you would want WSL v2 using Ubuntu 20.04 at a minimum for the services module to work the way you and him are trying to use it.

1 Like

Right, v2 is definitely required, but IIRC systemd did work on v2. You need to add

[boot]
systemd=true

to /etc/wsl.conf though.

Advanced settings configuration in WSL | Microsoft Learn

1 Like

on CMD I got this :

C:\Users\( user )>wsl -l -v

 NAME                   STATE           VERSION
* docker-desktop         Stopped         2
  docker-desktop-data    Stopped         2
  Ubuntu                 Running         1

and on wsl I got this :

user@user-PC:~$ wsl -l -v
WSL
Wsman Shell commandLine, version 0.2.1```

From inside wsl, run cat /etc/lsb-release and tell us the output.

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=22.04
DISTRIB_CODENAME=jammy
DISTRIB_DESCRIPTION=“Ubuntu 22.04.4 LTS”

1 Like

Since docker-desktop is running on WSL v2, we know that v2 is installed, but your Ubuntu instance is still running on v1.

wsl --set-version Ubuntu 2 will fix the WSL version it’s running on. Then go in and modify the /etc/wsl.conf file to start systemd on boot. Restart your instance to make sure changes take effect, and then run systemctl status nginx to see if you get any kind of systemd error.

Then try running your playbook again.

You might also want to run wsl --set-default-version 2 to make sure all future instances default to v2.

2 Likes

Yeah, you should be able to make this work.

High level steps:

  1. Windows CMD: Shutdown your current WSL Instance wsl --shutdown
  2. Windows CMD: Convert your Ubuntu instance to WSL 2 wsl --set-version Ubuntu 2
  3. Windows CMD: Start your Ubuntu instance again wsl -d Ubuntu

If you use the service module in your Ansible playbook, I believe it should work. If not, let us know. You may still need to do more modifications to your Ubuntu system files and restart WSL again.

1 Like

According to the Stack Overflow link I posted above, Ubuntu 20.04 may have a built in fall-back mechanism to handle the ansible.built-in.service module. So, enabling systemd MAY not be necessary.

I’d say, convert the WSL Ubuntu Distribution to version 2, test, and if it still doesn’t work then try enabling systemd.

I believe in the least number of changes necessary to make something new work.

It’s been a while since I’ve played with WSL + SystemD, so it may or may not be enough. According to my notes from the last time I actually played with it, I used Distrod to install Fedora 36 with SystemD. Then my manager found out and had a sandbox VM created for me to use instead, lol. So, I don’t remember if SystemD worked with just vanilla WSL v2, or if Distrod was required. ¯\_(ツ)_/¯

I mainly remember using Distrod so I could use Fedora, not because of the SystemD support.

1 Like