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

Ansible provisioner doesn't allow execution of raw powershell commands #4596

Closed
fbsdmon opened this issue Feb 26, 2017 · 14 comments
Closed

Ansible provisioner doesn't allow execution of raw powershell commands #4596

fbsdmon opened this issue Feb 26, 2017 · 14 comments

Comments

@fbsdmon
Copy link

fbsdmon commented Feb 26, 2017

I am having problems executing raw PowerShell commands via Packer's Ansible provisioner.
Example: I can't disable the Windows firewall by running raw: Set-NetFirewallProfile -Enabled False, but I can list a directory by running raw: dir or set a registry key with Ansible's win_regedit module.

Here is my full test setup and packer logs:

@fbsdmon
Copy link
Author

fbsdmon commented Feb 27, 2017

#3911 Feature: allow Ansible provisioner to specify usage of WinRM instead of SSH
#4209 provisioner/ansible: assume scp target is file (resolves winrm incompatibility)

@bhcleek
Copy link
Contributor

bhcleek commented Apr 22, 2017

When you run the Set-NetFirewallProfile -Enabled False command manually, what's the result? If you run it twice in a row, is the exit code for each run 0?

@fbsdmon
Copy link
Author

fbsdmon commented Apr 24, 2017

Manually, the command works. It also works when provisioning directly with Ansible (not via Packer).

PS C:\Users\Administrator> Set-NetFirewallProfile -Enabled False
PS C:\Users\Administrator> Write-Host $?
True
PS C:\Users\Administrator> Set-NetFirewallProfile -Enabled False
PS C:\Users\Administrator> Write-Host $?
True

@bhcleek
Copy link
Contributor

bhcleek commented Apr 30, 2017

Is the winrm_user specified in the provisioner section an administrator on the machine?

@fbsdmon
Copy link
Author

fbsdmon commented May 2, 2017

The ansible provisioner only supports user and that is specified.
The builder supports winrm_username and that is specified as well.
Please see the link to my packet template I provided in the issue description.

@bhcleek
Copy link
Contributor

bhcleek commented May 2, 2017

I see that they are the same (as they should be), but my question is about whether or not that user has permission to execute the commands that are failing.

@fbsdmon
Copy link
Author

fbsdmon commented May 4, 2017

Yes!
The ec2-bootstrap.ps1 script I added create's the user and adds it to the Administrators group, right after enabling WinRM. And as I said, I can add/edit the registry and do all other admin level tasks, the only thing I can't do is execute powershell scripts/commands via raw module.

@bhcleek
Copy link
Contributor

bhcleek commented May 4, 2017

I see; I'd missed the bootstrap script. Thanks for pointing it out. The raw task module works, as you can see by the dir listing in your output. I'll try to duplicate this independently.

@fbsdmon
Copy link
Author

fbsdmon commented May 5, 2017

Yes, the raw module works. The issue is when I try to execute powershell commands via raw.
Thanks for looking into this. Currently I have to provision my AMI's manually :(

@bhcleek
Copy link
Contributor

bhcleek commented May 25, 2017

I've tried to duplicate this, but am currently running into problems introduced by Ansible 2.3. Can you verify whether this happens with a more common cmdlet (e.g. Get-Help)?

@bhcleek
Copy link
Contributor

bhcleek commented Jun 7, 2017

I can duplicate this. From what I can tell, it's because the raw won't execute in a Powershell environment. I'd suggest either executing powershell -Command "& {Set-NetFirewallProfile -Enabled False}" or else use the win_shell module.

@fbsdmon
Copy link
Author

fbsdmon commented Oct 23, 2017

Ansible 2.4 + Packer 1.1.0 + using win_shell instead of raw = works!
Thanks!!

@SwampDragons
Copy link
Contributor

Closing since the issue had a workaround

@ghost
Copy link

ghost commented Mar 30, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Mar 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants