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

ConfigureRemotingForAnsible.ps1 and upgrade_to_ps3.ps1 chicken/egg problem #10509

Closed
breathe opened this issue Mar 20, 2015 · 5 comments
Closed
Labels
affects_2.2 This issue/PR affects Ansible v2.2 affects_2.3 This issue/PR affects Ansible v2.3 feature This issue/PR relates to a feature request. windows Windows community

Comments

@breathe
Copy link

breathe commented Mar 20, 2015

ISSUE TYPE

Feature Idea

COMPONENT NAME

core

ANSIBLE VERSION

2.2

CONFIGURATION
OS / ENVIRONMENT
SUMMARY

The example powershell script for setting up winrm on a windows host in a manner suitable for management with ansible requires powershell 3: https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1

meanwhile this sample powershell script to upgrade to powershell3 suggests that it can be run inside an ansible task (in the comments at the top):
https://github.com/cchurch/ansible/blob/devel/examples/scripts/upgrade_to_ps3.ps1

Chicken and egg though -- you can't run upgrade_to_ps3.ps1 via ansible because you can't setup winrm for ansible correctly with ConfigureRemotingForAnsible.ps1 since ConfigureRemotingForAnsible.ps1 requires powershell 3 ...

Would be nice if ConfigureRemotingForAnsible.ps1 didn't require powershell 3 -- then getting ansible working on a node would be simpler as ansible itself could be used to get the node to powershell3 ...

STEPS TO REPRODUCE
EXPECTED RESULTS
ACTUAL RESULTS
@cchurch cchurch added feature_idea windows Windows community labels Mar 21, 2015
@cchurch
Copy link
Contributor

cchurch commented Mar 21, 2015

The comments in upgrade_to_ps3.ps1 were there before the ConfigureRemotingForAnsible.ps1 script even existed, and the steps to configure remoting were only described in the documentation at that time. It may make sense to remove those comments to avoid confusion.

What is your target OS?

@breathe
Copy link
Author

breathe commented Mar 23, 2015

I'm targeting windows 7 (which comes with powershell 2) and higher. I'm not super familiar with powershell -- I see that ConfigureRemotingForAnsible.ps1 explicitly checks for greater-than or equal to version 3 -- is there anything in that script which actually depends on such a shell version? It would be be nice to deploy powershell >=3 via ansible if it were possible as the upgrade process for powershell requires upgrading to compatible dotnet which requires a reboot. Its easier and cleaner to orchestrate automation like that with ansible than without ... I'm currently using a script which creates a scheduled task that runs ONSTART to get hosts from clean windows install up to powershell 4 without intervention, then calls ConfigureRemotingForAnsible. Not the cleanest thing but I'll go with it if there's no other way ...

@trondhindenes
Copy link
Contributor

@breathe One reason we didn't use configure....ps1 to optionally install the required powershell version, is that changing the WMF version (Powershell is part of WMF) requires a reboot. I didn't have to go down the path of having to create a script that would persist between reboots since this is meant to be a quick and easy config-script.

I have not tested the configure..ps1 script on PowerShell 2.0, there's a good chance it will work (maybe a little bit of tweaking is required).

@jimi-c jimi-c removed the P3 label Dec 7, 2015
@ansibot ansibot added the affects_2.2 This issue/PR affects Ansible v2.2 label Sep 8, 2016
@ansibot ansibot added the affects_2.3 This issue/PR affects Ansible v2.3 label Dec 13, 2016
@dagwieers
Copy link
Contributor

dagwieers commented Feb 3, 2017

@breathe Not really a chicken-and-egg problem, because you can use the script, raw or win_psexec modules to run tasks without the need for Powershell 3 ! But you will have to enable WinRM yourself manually. That is always the first step, which means running a few things from the ConfigureRemotingForAnsible.ps1 !

The script-module is powershell-agnostic as well (like it is on Unix), which would allow for this as soon as WinRM is configured:

- hosts: old_windows
  gather_facts: no
  tasks:
  - script:  files/upgrade_to_ps3.ps1

So the following task would work on a Powershell 2 system:

- hosts: old_windows
  gather_facts: no
  tasks:
  - raw: |
      <powershell commands or script content>

In fact what should work equally well is this:

- hosts: old_windows
  gather_facts: no
  tasks:
  - raw: {{ lookup("file', 'files/upgrade_to_ps3.ps1') }}

Or you can run a script directly from a network share

- hosts: old_windows
  gather_facts: no
  tasks:
  - raw: powershell.exe -file \\system\share\path\upgrade_to_ps3.ps1

Good luck, report back and possibly send in a PR with suggested changes to the documentation !

@ansibot ansibot added needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. labels Apr 4, 2017
@ansibot
Copy link
Contributor

ansibot commented Apr 4, 2017

@breathe Greetings! Thanks for taking the time to open this issue. In order for the community to handle your issue effectively, we need a bit more information.

Here are the items we could not find in your description:

  • issue type
  • ansible version
  • component name

Please set the description of this issue with this template:
https://raw.githubusercontent.com/ansible/ansible/devel/.github/ISSUE_TEMPLATE.md

click here for bot help

@ansibot ansibot removed needs_info This issue requires further information. Please answer any outstanding questions. needs_template This issue/PR has an incomplete description. Please fill in the proposed template correctly. labels Apr 4, 2017
@breathe breathe closed this as completed Apr 13, 2017
@ansibot ansibot added feature This issue/PR relates to a feature request. and removed feature_idea labels Mar 2, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.2 This issue/PR affects Ansible v2.2 affects_2.3 This issue/PR affects Ansible v2.3 feature This issue/PR relates to a feature request. windows Windows community
Projects
None yet
Development

No branches or pull requests

6 participants