WIndows PowerShell provisioning script not being executed - windows

I'm deploying a Windows 2012 R2 VSI and need to be able to manage it using Ansible.
I'm using this Ansible sample script ConfigureRemotingForAnsible.ps1 although renamed and have the script hosted on SL Object storage. I specify a postinstall script URL including https (which is supposed to cause the execution of the script after downloading) during the order.
After the Windows VSI is ready I attempt to run a win-ping as follows:
- name: ad1 ready
gather_facts: false
tags: setup
hosts: ad1
tasks:
- name: ping the windows vsi
win_ping:
This fails with the output:
fatal: [169.55.189.16]: UNREACHABLE! => {"changed": false, "msg": "ssl: HTTPSConnectionPool(host='169.55.189.16', port=5986): Max retries exceeded with url: /wsman (Caused by NewConnectionError('<requests.packages.urllib3.connection.VerifiedHTTPSConnection object at 0x107c0b310>: Failed to establish a new connection: [Errno 61] Connection refused',))", "unreachable": true}
If I connect to the system and look in c:\PostInstall I see my script has been downloaded. If I then open a PowerShell and run the script, I am able to then run the above win-ping successfully.
This tells me that the script is downloaded cleanly and is apparently correct, but is not being executed in spite of the https in the postinstall URL.
I can't find any documentation on requirements of the postinstall script for windows, but I'm wondering if the problem is that I'm using a PowerShell script, and that the post provision process tries to run this in a standard CMD shell.
Does anyone have any ideas or thoughts on what could be wrong?

It should work with powershell succesfully, you should be able to see the logs of the powershell execution in "C:\postInstallScript.log" perhaps it contains more information about the error.
Anyway if you are still facing this issue I suggest you to open a ticket in Softlayer with "hardware issue" subject, because the issue is likely due to a restriction in the windows machine which is not allowing to execute the script.
Regards

I believe the problem with PowerShell as a provisioning script is the default configuration of PowerShell requires a signed PowerShell script to execute (with no arguments defined). If the PowerShell script is not signed, the execution policy has to be changed on the server, or flags passed to the PowerShell interpreter to allow execution.

Related

libssh vs paramiko - ios_facts are different when running Ansible playbooks

I have a playbook I am writing that automates the install of firmware to our fleet of C2960Xs.
I recently moved the location of the Ansible server I am using from my homelab to a VM in Azure. We have security rules on our sites to only allow remote connection on a specific non-default port. After reading, I discovered that means I need to use libssh and not paramiko for remote commands.
I have a specific task I am running, and when running it returns:
fatal: [HOSTNAME]: FAILED! => {
"msg": "The conditional check 'ansible_net_filesystems_info['flash:'].spacefree_kb >
firmware_image_size' failed. The error was: error while evaluating
conditional (ansible_net_filesystems_info['flash:'].spacefree_kb >
firmware_image_size): 'ansible_net_filesystems_info' is undefined" }
I then compared the 'before' and 'after' for what facts are being stored at the beginning of the playbook. I found that using Paramiko, I seem to have a TON more detail compared to the facts being gathered via libssh.
One of which being the variable ansible_net_filesystems_info that my playbook references.
Is there a workaround for this process? The idea being to verify there is free space on the switch before moving an archive to the switch for unzipping.
Under the cisco.ios.ios_facts documentation, you can specify the types of facts you want to pull. I added the line: >gather_subset: all

Run an IBM OS/2 related command on remote server through Ansible playbook but hangs, no response

I have a playbook, as below:
tasks:
- name: Execute a program_A on managed node
win_command: 'D:test\program_A.exe'
I run this playbook but hung and no any response on managed node (Windows 2012). (i.e. there is a program_A.exe process generated on managed node but no response, it's CPU usage time is always 0%)
I also tired to replace win_command by win_shell module, raw module, but it still hung and no response on managed node...
When I try to open a command window on the managed node to run D:\test\program_A.exe directly, the program_A.exe was successfully executed.
What could be wrong?
Make sure the exe file is executed by the same privilege. eg. when you directly execute it, you are using Administrator, but in playbook, you may use guest rule.

Starting Bitbucket Server in Ansible

I'm using Vagrant and Ansible to create my Bitbucket Server on Ubuntu 15.10. I have the server setup complete and working but I have to manually run the start-webapp.sh script to start the server each time I reprovision the server.
I have the following task in my Bitbucket role in Ansible and when I increase the verbosity I can see that I get a positive response from the server saying it will be running at http://localhost/ but when I go to the URL the server isn't on. If I then SSH in to the server and run the script myself, getting the exact same response after running the script I can see the startup webpage.
- name: Start the Bitbucket Server
become: yes
shell: /bitbucket-server/atlassian-bitbucket-4.7.1/bin/start-webapp.sh
Any advice would be great on how to fix this.
Thanks,
Sam
Probably better to change that to an init script and use the service module to start it. For example, see this role for installing bitbucket...
Otherwise, you're subject to HUP and other issues from running processes under an ephemeral session.

win_get_url fails to get the file from the url to a remote windows server 2012 node

I need to copy a file from a jenkins server to a remote Windows server 2012 machine using win_get_url
My playbook looks as follows:
hosts: windows_ip tasks:
name: Deploy to windows
win_get_url:
url: 'http://(jenkins_server_ip)/jenkins/view/Trunk/job/router/lastSuccessfulBuild/artifact/router/conf/router-service-context.xml'
dest: 'D:\router'
However it gives the following error:
fatal: [windows_ip]: FAILED! => {"changed": false, "failed": true, "msg": "Error downloading http://(jenkins_server_ip)/jenkins/view/Trunk/job/router/lastSuccessfulBuild/artifact/router/conf/router-service-context.xml to D:\router Exception calling \"DownloadFile\" with \"2\" argument(s): \"An exception occurred during a WebClient request.\""}
What is the issue over here?
For anyone else that comes across this issue, the problem is that the underlying powershell script will not create the destination directory if it does not exist.
I'd troubleshoot this by looking at the exact script. First. make sure ansible leaves it's script on the target node by running the following on the control node:
export ANSIBLE_KEEP_REMOTE_FILES=1
Re-run your playbook, and then log on to the windows box. Ansible's files will be in C:\users\\appdata\local\temp\ansiblexxxxx
Run/debug the script locally to figure out whats happening.

Bamboo remote build agent cannot find powershell.exe after installing nodejs

I just installed nodejs on one of my build servers (Win Server 2008 R2) which hosts a Bamboo remote agent. After completing the installation and doing a reboot I got stuck in the following situation:
The remote Bamboo build agent is running as a windows service with user MyDomain\MyUser. When a build with an inline powershell task is executing it fails with the error (from the build agent log):
com.atlassian.utils.process.ProcessNotStartedException: powershell could not be started
...
java.io.IOException: Cannot run program "powershell"
...
java.io.IOException: CreateProcess error=2, The system cannot find the file specified
Loggin on to the server as MyDomain\MyUser, I have checked that powershell is in the path:
where powershell
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
I have tried to restart the service and reboot the machine multiple times. No luck. The only thing that works is if I execute my scripts as a bat file with an absolute path to powershell - but I do not want that.
I have searched for solutions on this, but even though this one seems related: Hudson cannot find powershell after update to powershell 3 - the proposed solutions do not work.
What am I missing here?
If you do a default installation of nodejs you will see that it adds nodejs and npm to the path. Sometimes I have seen that the installer adds a user variable named PATH - it might be that the Bamboo agent decides to read the user path without "merging" it with the system path. I think it would be worth a try to give that a look.
As per Atlassian support page, this is related to a bug in Java Service Wrapper. I tried Workaround-2 since there was no user PATH variable in my system. I had to uninstall bamboo agent service and Java 64 versions from the agent machine to apply the workaround-2.

Resources