# Ansible insists on using PowerShell instead of bash

**URL:** <https://forum.ansible.com/t/ansible-insists-on-using-powershell-instead-of-bash/40209>\
**Category:** Get Help\
**Tags:** windows, awx\
**Created:** [February 12, 2025, 11:17am UTC](https://forum.ansible.com/t/ansible-insists-on-using-powershell-instead-of-bash/40209 "2025-02-12T11:17:30Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![pacyt](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/pacyt/32/7567_2.png) [@pacyt](https://forum.ansible.com/u/pacyt)\
**Post date:** [February 12, 2025, 11:17am UTC](https://forum.ansible.com/t/ansible-insists-on-using-powershell-instead-of-bash/40209/1 "2025-02-12T11:17:30Z")

</div>

I’ve encountered a challenging problem while working with Ansible and I wanted to ask for your help and advice.

While running an Ansible role that registers Windows hosts in Zabbix, Ansible insists on using PowerShell. This causes errors because PowerShell is not available on the Zabbix server.

Here is a fragment of the error log:

> Task path: /runner/project/windows/roles/zabbix\_register\_windows\_host/tasks/main.yml:12  
> fatal: [10.10.10.10 → zabbix server]: FAILED! =\> {  
> “changed”: false,  
> “module\_stderr”: “/bin/sh: line 1: PowerShell: command not found\n”,  
> “module\_stdout”: “”,  
> “msg”: “MODULE FAILURE\nSee stdout/stderr for the exact error”,  
> “rc”: 0  
> }  
> …ignoring  
> redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi  
> ESTABLISH LOCAL CONNECTION FOR USER: root  
> EXEC /bin/sh -c 'PowerShell -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -EncodedCommand vAHQAIAAkAD8AKQAgAHsAIABJAGYAIAAoAEcAZQB0AC0AVgBhAHIAaQBhAGIAbABlACAATABBAFMAVABFAFgASQBUAEMATwBEAEUAIAAtAEUAcgBy…  
> Using module file /root/.ansible/collections/ansible\_collections/community/zabbix/plugins/modules/zabbix\_host.py  
> PUT /root/.ansible/tmp/ansible-local-229g6e\_e1u/tmp6dn9lqx6 TO /runner/project/.\AnsiballZ\_zabbix\_host.ps1  
> EXEC /bin/sh -c 'PowerShell -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -EncodedCommand UwBlABfAC4ASQBuAHYAbwBjAGEAdABpAG8AbgBJAG4AZgBvAC4AUABvAHMAaQB0AGkAbwBuAE0AZQBzAHMAYQBnAGUAKQAKAH0ACgBFAGwAcwBl…

**What I’ve tried:**

Setting _ansible\_shell\_executable: /bin/bash_ and _ansible\_shell\_type: cmd_ at the task’s level in the role:

> * * *
> 
> - name: Set API token  
> ansible.builtin.set\_fact:  
> ansible\_zabbix\_auth\_key: “{{ zabbix\_auth\_key }}”  
> ansible\_zabbix\_url: “{{ ansible\_zabbix\_url }}”
> 
> - name: Register Windows host in Zabbix  
> vars:  
> ansible\_network\_os: community.zabbix.zabbix  
> ansible\_connection: httpapi  
> ansible\_httpapi\_port: 443  
> ansible\_httpapi\_use\_ssl: true  
> ansible\_httpapi\_validate\_certs: false  
> ansible\_zabbix\_url\_path: “”  
> community.zabbix.zabbix\_host:  
> host\_name: “{{ inventory\_hostname }}”  
> visible\_name: “{{ inventory\_hostname }}”  
> host\_groups:  
> - “Windows servers”  
> link\_templates:  
> - “Windows by Zabbix agent”  
> …  
> status: enabled  
> state: present  
> ignore\_errors: yes  
> delegate\_to: “{{ ansible\_zabbix\_url }}”  
> become: false

Unfortunately, none of these suggestions solved the problem. Ansible still tries to use PowerShell.

What is important to mention,

- The playbook is run with `ansible_shell_type: powershell` at the playbook level and we cannot remove it, because the above role is part of a larger playbook where earlier tasks need to have the PowerShell shell set.

How can I work around this issue and what else can I check? Any help would be greatly appreciated! 🙏

We use Zabbix server 7.0.8 and AWX 24.6.1

Thanks in advance for any advice and suggestions!

---

<div class="post-metadata">

**Author:** ![markuman](https://avatars.discourse-cdn.com/v4/letter/m/7bcc69/32.png) [@markuman](https://forum.ansible.com/u/markuman)\
**Post date:** [February 12, 2025, 2:33pm UTC](https://forum.ansible.com/t/ansible-insists-on-using-powershell-instead-of-bash/40209/2 "2025-02-12T14:33:10Z")

</div>

I guess this is the error

```auto
 delegate_to: “{{ ansible_zabbix_url }}”

```

just remove it from the task. The ` community.zabbix.zabbix_host:` works against the http API of zabbix itself. There is no need that you leave your host/ansible controle node for that task.

---

<div class="post-metadata">

**Author:** ![flowerysong](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/flowerysong/32/2305_2.png) [@flowerysong](https://forum.ansible.com/u/flowerysong)\
**Post date:** [February 12, 2025, 2:53pm UTC](https://forum.ansible.com/t/ansible-insists-on-using-powershell-instead-of-bash/40209/3 "2025-02-12T14:53:21Z")

</div>

> [@markuman](#):
>
> The ` community.zabbix.zabbix_host:` works against the http API of zabbix itself. There is no need that you leave your host/ansible controle node for that task.

This doesn’t “leave” the control node, it uses the network-style httpapi model where the module always runs on the control node but connects to the target host using HTTP. If they don’t delegate the task the module will try to connect to the original target host instead of the Zabbix host, which will not work.

---

<div class="post-metadata">

**Author:** ![jkruza](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jkruza](https://forum.ansible.com/u/jkruza)\
**Post date:** [February 21, 2025, 8:23am UTC](https://forum.ansible.com/t/ansible-insists-on-using-powershell-instead-of-bash/40209/4 "2025-02-21T08:23:09Z")

</div>

NOTE: I work on same team as OP

@markuman , using `delegate_to` is a legitimate way to point the module to Zabbix API URL, as documented here: [community.zabbix.zabbix\_host module – Create/update/delete Zabbix hosts — Ansible Community Documentation](https://docs.ansible.com/ansible/latest/collections/community/zabbix/zabbix_host_module.html)

The problem seems to be here:

> redirecting (type: connection) ansible.builtin.httpapi to ansible.netcommon.httpapi  
> ESTABLISH LOCAL CONNECTION FOR USER: root  
> EXEC /bin/sh -c 'PowerShell -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -EncodedCommand

It’s using `ansible.netcommon.httpapi`, (see reply from @flowerysong), and code is to be executed on control node (note the “sh” command).  
But for some reason it’s wrapping the actual task code as PowerShell.

I think what we are looking for is to force it to generate the bash code not PowerShell one, that’s why OP tried to override it with forcing shell type and executable.  
Any idea why this didn’t work?

Or maybe we just set it in wrong place/way? What is the proper way to force Ansible to generate sh code?

---

<div class="post-metadata">

**Author:** ![basicvglass](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/basicvglass/32/7647_2.png) [@basicvglass](https://forum.ansible.com/u/basicvglass)\
**Post date:** [February 21, 2025, 12:34pm UTC](https://forum.ansible.com/t/ansible-insists-on-using-powershell-instead-of-bash/40209/5 "2025-02-21T12:34:50Z")

</div>

I’m not familiar with zabbix or ansible.netcommon.httpapi, but have you confirmed the content of “ansible\_zabbix\_url”

```auto
- debug:
    var: ansible_zabbix_url

```

Your set\_fact line is putting the contents of ansible\_zabbix\_url back in the same variable, unless that is an error made only in your post, and not in your actual playbook.

---

<div class="post-metadata">

**Author:** ![jkruza](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jkruza](https://forum.ansible.com/u/jkruza)\
**Post date:** [February 21, 2025, 3:39pm UTC](https://forum.ansible.com/t/ansible-insists-on-using-powershell-instead-of-bash/40209/6 "2025-02-21T15:39:15Z")

</div>

good point, however this was just edit for this post.

Anyway, this does not affect the issue.

---

<div class="post-metadata">

**Author:** ![basicvglass](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/basicvglass/32/7647_2.png) [@basicvglass](https://forum.ansible.com/u/basicvglass)\
**Post date:** [February 21, 2025, 4:49pm UTC](https://forum.ansible.com/t/ansible-insists-on-using-powershell-instead-of-bash/40209/7 "2025-02-21T16:49:43Z")

</div>

If this is a bug as described, You can try running another play at the same point instead of doing the delegate\_to. You’d then iterate through the windows hosts, which I assume are in a group of their own and add them that way. You can register a var to ensure you only add hosts that have completed the play up to that point. You’d have to modify your role to expect that the play is being run with the zabbix host as the original target. Example play without using a role.

```auto
- name:
  hosts: <windows hosts>
  tasks:
    ...
    - ansible.builtin.set_fact:
        host_up: true

- name: Add windows hosts to zabbix
  hosts: <zabbix_host>
  vars:
    ansible_network_os: community.zabbix.zabbix
    ansible_connection: httpapi
    ansible_httpapi_port: 443
    ansible_httpapi_use_ssl: true
    ansible_httpapi_validate_certs: false
    ansible_zabbix_url_path: “”
  tasks:
    - name: Register Windows host in Zabbix
      when: 'hostvars[win_hostname]["host_up"] is defined'
      community.zabbix.zabbix_host:
        host_name: “{{ win_hostname }}”
        visible_name: “{{ win_hostname }}”
        host_groups:
        - “Windows servers”
        link_templates:
        - “Windows by Zabbix agent”
        …
        status: enabled
        state: present
      ignore_errors: yes
      become: false
      loop: '{{ groups[<name of windows host groups>] }}'
      loop_control:
        loop_var: 'win_hostname'

- name: Start other tasks of the original play here
  hosts: <windows hosts>
  ...

```

---

<div class="post-metadata">

**Author:** ![basicvglass](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/basicvglass/32/7647_2.png) [@basicvglass](https://forum.ansible.com/u/basicvglass)\
**Post date:** [February 21, 2025, 5:29pm UTC](https://forum.ansible.com/t/ansible-insists-on-using-powershell-instead-of-bash/40209/8 "2025-02-21T17:29:21Z")

</div>

For parallelism, you can do the above with the windows hosts as the original target still, but change the ansible\_shell\_type for the var at the play level, and try to do the delegate\_to again.

---

<div class="post-metadata">

**Author:** ![hugonz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/hugonz/32/503_2.png) [@hugonz](https://forum.ansible.com/u/hugonz)\
**Post date:** [February 21, 2025, 6:30pm UTC](https://forum.ansible.com/t/ansible-insists-on-using-powershell-instead-of-bash/40209/9 "2025-02-21T18:30:23Z")

</div>

Since you are iterating through the Windows hosts, some of the connection variables could be getting used fot the connection to localhost. Can you post some sanitized inventory? This should not normally be a problem, unless you have explicitly added `localhost` to your inventory.
