Wont be able to ping Windows Machines Via Linux Ansible Server

276 views
Skip to first unread message

shilpa motghare

unread,
Nov 21, 2017, 9:03:40 AM11/21/17
to Ansible Project

Guys Need help here I am posting /etc/ansible/hosts file for windows entry is
[windows]
Lenovo-PC

Lenovo-PC entry is added in my /etc/hosts file

AND

/etc/ansible/windows.yml file is
ansible_user: Administrator
ansible_password:
ansible_port: 5985
ansible_connection: winrm
ansible_winrm_scheme: http
ansible_winrm_server_cert_validation: ignore

and run command
ansible windows -m win_ping

But Still GET ERROR

Lenovo-PC | UNREACHABLE! => {
"changed": false,
"msg": "Failed to connect to the host via ssh: ssh: connect to host lenovo-pc port 22: Connection refused\r\n",
"unreachable": true
}

PLEASE HELLPPP!!!!!!!!

Soniya panwar

unread,
Nov 23, 2017, 1:56:05 AM11/23/17
to Ansible Project
Hello,

There could be a few things not correctly configured or missed that could result into below error:


First and foremost, while installing Ansible, did you resolve dependencies for paramiko, PyYAML, Jinja2 and httplib2 packages? If not, you may execute below commands on the linux machine with Ansible installation.

1.       $ sudo pip install paramiko PyYAML Jinja2 httplib2

2.       $ pip install "pywinrm>=0.1.1"

3.       $ pip install http://github.com/diyan/pywinrm/archive/master.zip#egg=pywinrm

 

Secondly, verify that the version of Microsoft.NET Framework is 4.0 or later. If not you may follow below steps to get it upgraded.

1.       Click on Start -> Control Panel -> Program and Features -> Add or Remove Programs. 

2.       Scroll down to the M's and look for Microsoft .NET Framework.  If you don't have version 4.0 or later, download and install it from here “https://www.microsoft.com/en-us/download/details.aspx?id=30653”.

 

Thirdly, the ansible_user used in windows.yml file should have admin privileges on remote windows machine to make connection to PowerShell. You may follow below steps to grant admin privileges to the user, if not provided already.

1.       Click on Start -> Control Panel -> User Accounts -> Manage User Accounts.

2.       Select your new account and click on Properties. 

3.       Click on the Group Membership tab and change the Group Membership from Standard User to Administrator. 

4.       Click OK, OK and Close.  Restart computer. 

Note:- The remote computer need not be logged into this account for Ansible to make a remote connection to PowerShell, but the account must exist.

 

Last but not the least, you need to execute a PowerShell script in order to enable WinRM/PS Remoting. Below are the steps to be followed.

1.       Start PowerShell and run the command Set-ExecutionPolicy  -ExecutionPolicy Unrestricted

2.       Download PowerShell script (named ConfigureRemotingForAnsible.ps1) for enabling WinRM/PSRemoting.  You can get the most recent version here:
https://github.com/ansible/ansible/blob/devel/examples/scripts/ConfigureRemotingForAnsible.ps1”. 

3.       And then run the PowerShell script :

                    •  powershell.exe -File ConfigureRemotingForAnsible.ps1

              Pass the -CertValidityDays option to customize the expiration date of the generated certificate:

                    •  powershell.exe -File ConfigureRemotingForAnsible.ps1 -CertValidityDays 100

             Pass the -EnableCredSSP switch to enable CredSSP as an authentication option:

                   • powershell.exe -File ConfigureRemotingForAnsible.ps1 –EnableCredSSP

             Pass the -ForceNewSSLCert switch to force a new SSL certificate to be attached to an already existing winrm listener.

                   • powershell.exe -File ConfigureRemotingForAnsible.ps1 –ForceNewSSLCert

            Pass the -SkipNetworkProfileCheck switch to configure winrm to listen on PUBLIC zone interfaces.

                  • powershell.exe -File ConfigureRemotingForAnsible.ps1 –SkipNetworkProfileCheck

            Additionally the -Verbose option can be used to get more information on screen about what it is doing

                  • powershell.exe -File ConfigureRemotingForAnsible.ps1 –Verbose

 

Output of this command should be like this:

VERBOSE: Verifying WinRM service.

VERBOSE: PS Remoting is already enabled.

VERBOSE: SSL listener is already active.

VERBOSE: Basic auth is already enabled.

VERBOSE: Firewall rule already exists to allow WinRM HTTPS.

VERBOSE: HTTP: Enabled | HTTPS: Enabled

VERBOSE: PS Remoting has been successfully configured for Ansible.

 

                4.  Run the PowerShell command Set-ExecutionPolicy -ExecutionPolicy Restricted.

                5.  Close PowerShell.

If all of the above steps are performed correctly, you should get a successful ping-pong from your remote windows node.

 


Thanks

Soniya

J Hawkesworth

unread,
Nov 26, 2017, 12:53:44 PM11/26/17
to Ansible Project
Hey I think you have the settings right, you just need to move
/etc/ansible/windows.yml to /etc/ansible/group_vars/windows.yml

You have created the group called windows in your inventory
[windows]
Lenovo-PC

But the group variables aren't taking effect because they aren't in the location ansible expects (in group_vars/<name_of_group>.yml in sub dir under the dir where your inventory file is.

I think if you move the file it will all start working.

Hope this helps,

Jon

Selva Kumar

unread,
Dec 4, 2017, 9:55:51 AM12/4/17
to Ansible Project
I also hitting same issue. My /etc/ansible/hosts entry:

[windows]
10.x.x.33

cat /etc/ansible/groups_vars/windows.yml

ansible_user: Administrator
ansible_password: 
ansible_port: 5986
ansible_connection: winrm
# The following is necessary for Python 2.7.9+ when using default WinRM self-signed certificates:
ansible_winrm_server_cert_validation: ignore

When I do ansible windows -m win_ping, getting below error:

10.x.x.33 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: ssh: connect to host 10.x.x7.33 port 22: Connection timed out\r\n",
    "unreachable": true
}

10.x.x.33 is a windows host and not sure why complaining about ssh error.

I did check and confirm the steps mentioned by Sonia and Jon, but still nu luck. Please help.

shilpa motghare

unread,
Dec 4, 2017, 11:49:00 PM12/4/17
to ansible...@googlegroups.com
Thanks 

It works, I am able to do ping pong to my windows client but not able to install a .exe packages through ansible this is my output

ansible windows  -m win_ping
Lenovo-PC | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

And my windows.yml file is:
ansible_user: Administrator
ansible_password: ********
ansible_ssh_port: 5985
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore

but now I want to install a notepad++  on windows via ansible this is my notepad.yml file:

- name: test raw module
  hosts: windows
  tasks:
    - name: Install Notepad plus
      win_package:
        path: C:\tmp\notepad.exe
        product_id:
        state: present
It take too much time for the output and it come  with error the screenshot of error I am attaching here.

Please help me why this happening.

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/jnE-wYRvCl8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/29d3ae1e-4ee9-456b-9083-9564a287c7ab%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

WhatsApp Image 2017-11-24 at 10.21.25 AM.jpeg

shilpa motghare

unread,
Dec 4, 2017, 11:49:00 PM12/4/17
to ansible...@googlegroups.com
Thanks 

It works, I am able to do ping pong to my windows client but not able to install a .exe packages through ansible this is my output

ansible windows  -m win_ping
Lenovo-PC | SUCCESS => {
    "changed": false,
    "ping": "pong"
}

And my windows.yml file is:
ansible_user: Administrator
ansible_password: ********
ansible_ssh_port: 5985
ansible_connection: winrm
ansible_winrm_server_cert_validation: ignore

but now I want to install a notepad++  on windows via ansible this is my notepad.yml file:

- name: test raw module
  hosts: windows
  tasks:
    - name: Install Notepad plus
      win_package:
        path: C:\tmp\notepad.exe
        product_id:
        state: present
It take too much time for the output and it come  with error the screenshot of error I am attaching here.

Please help me why this happening.
On Thu, Nov 23, 2017 at 12:26 PM, Soniya panwar <soniyap...@gmail.com> wrote:

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/jnE-wYRvCl8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

J Hawkesworth

unread,
Dec 8, 2017, 7:00:21 AM12/8/17
to Ansible Project
Not sure what c:\tmp\notepad.exe is in your example, but here is how I install notepad++

{{ deploy_dir }} is a staging location where I keep files to be installed.  I guess you could use C:\tmp for that if it makes sense for you.

the /S makes the notepad++ installer run in silent, or 'unattended' mode. Without this it will pop up a user interface on the target windows machine, which will never be visible, so the task will just and and eventually it will timeout, as you have seen.

A lot of windows installers need telling to run in silent/unattended mode otherwise they will do this.  Windows often assumes there is someone sitting in front of the computer installing software.

I'd suggest trying win_chocolatey module if you can as that makes installing many popular windows programs about as easy it can be.

Hope this helps,

Jon

- name: use win_get_url module to download notepad plus plus
  win_get_url
:
    url
: https://notepad-plus-plus.org/repository/7.x/7.5.3/npp.7.5.3.Installer.exe
    dest
: "{{ deploy_dir }}npp.7.5.3.Installer.exe"


- name: install notepad plus plus

  win_shell
: "{{ deploy_dir }}npp.7.5.3.Installer.exe /S"







To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.

shilpa motghare

unread,
Dec 8, 2017, 7:25:50 AM12/8/17
to ansible...@googlegroups.com
Hiii

Thanks for your reply 

[root@ansible-server ansible]# ansible-playbook notepad.yml  -vvv
Using /etc/ansible/ansible.cfg as config file
ERROR! 'win_get_url' is not a valid attribute for a Play

The error appears to have been in '/etc/ansible/notepad.yml': line 1, column 3, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:


- name: test raw module
  ^ here



This is  my yml file
[root@ansible-server ansible]# cat notepad.yml
- name: test raw module
  hosts: windows
  tasks:
  win_get_url:
    dest: "{{ C:\tmp }}npp.7.5.3.Installer.exe"


- name: install notepad plus plus

  win_shell: "{{ C:\tmp }}npp.7.5.3.Installer.exe /S"



getting this error


To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/6c1eb6e6-324d-4681-be98-ed8674b85592%40googlegroups.com.

J Hawkesworth

unread,
Dec 10, 2017, 2:41:40 AM12/10/17
to Ansible Project
I think you just have a syntax error, and need to put 'hosts' before 'tasks'.

I can't test this at the moment, but from memory the syntax would be as follows.

# start of playbook
- name: install notepad plus plus playbook
hosts: windows
tasks:
- name: fetch notepad-plus-plus installer


win_get_url:
url: https://notepad-plus-plus.org/repository/7.x/7.5.3/npp.7.5.3.Installer.exe
dest: "{{ C:\tmp }}npp.7.5.3.Installer.exe"

- name: install notepad plus plus
win_shell: "{{ C:\tmp }}npp.7.5.3.Installer.exe /S"

# end of playbook

Hope this helps,

Jon

shilpa motghare

unread,
Dec 11, 2017, 1:40:21 AM12/11/17
to ansible...@googlegroups.com
Thanks Dear

It works..

--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/jnE-wYRvCl8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-project+unsubscribe@googlegroups.com.
To post to this group, send email to ansible-project@googlegroups.com.

shilpa motghare

unread,
Dec 11, 2017, 1:41:30 AM12/11/17
to ansible...@googlegroups.com
I want to install a quick heal software on my machine
I m successful to install a notepad.exe
But in quickheal software first it ask me for the password 
Can anyone help me to make a .yml script for it

On Mon, Dec 11, 2017 at 12:10 PM, shilpa motghare <ssmot...@gmail.com> wrote:
Thanks Dear

It works..
Reply all
Reply to author
Forward
0 new messages