I need to create C:\MSI folder to put there msi files. Here is my task:
tasks:
- name: Copy *.msi files from ./MSI to C:\MSI
file: path=C:\MSI state=directory
But I got the error:
TASK [Copy *.msi files from ./MSI to C:\MSI] ***********************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: + ~~~~~~~~~~~~~~~
fatal: [agentsmith]: FAILED! => {"changed": false, "failed": true, "msg": "The term '/usr/bin/python' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again."}
and in verbose mode I see that File module for some reason puts /usr/bin/python to the Powershell script:
TASK [Copy *.msi files from ./MSI to C:\MSI] ***********************************
task path: /home/qaexpert/ansible-lab/tcagent.yml:8
<agentsmith> ESTABLISH WINRM CONNECTION FOR USER: Administrator on PORT 5986 TO agentsmith
<agentsmith> EXEC Set-StrictMode -Version Latest
(New-Item -Type Directory -Path $env:temp -Name "ansible-tmp-1477410445.62-187863101456896").FullName | Write-Host -Separator '';
<agentsmith> PUT "/tmp/tmpqOJYen" TO "C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1477410445.62-187863101456896\file.ps1"
<agentsmith> EXEC Set-StrictMode -Version Latest
Try
{
/usr/bin/python 'C:\Users\Administrator\AppData\Local\Temp\ansible-tmp-1477410445.62-187863101456896\file.ps1'
}
Catch
...
Ansible looks for /usr/bin/python because the file module needs Python installed on the target system. It is not possible to use normal Ansible modules for Windows target.
Look at the Ansible Windows documentation for details. On Windows hosts only modules listed in the “windows” subcategory of the Ansible module index are available.
To replace the regular file module use the win_file module.
Related
we have an Ansible script to deploy software on Windows. One of the task if to check the existence of a folder with win_stat command.
However, om some servers, the task throws an error when a path that doesn't exist is defined in the 'LIB' environment variable on the windows server (the path has nothing to do with what we check)
I'm able to reproduce with a dead simple script:
- hosts: all
gather_facts: no
tasks:
- name: Check addon folder
win_stat:
path: 'C:\temp\'
and the error is (with verbose):
The full traceback is:
(0) : Warning as Error: Invalid search path 'System.Collections.DictionaryEntry' specified in 'LIB environment variable' -- 'The system cannot find the path specified. '
(1) : using Microsoft.Win32.SafeHandles;
At line:408 char:5
+ Add-Type -TypeDefinition $link_util
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (Microsoft.Power...peCompilerError:AddTypeCompilerError) [Add-Type], Exception
+ FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand
ScriptStackTrace:
at Load-LinkUtils, <No file>: line 408
at <ScriptBlock>, <No file>: line 76
fatal: [IADCMP019]: FAILED! => {
"changed": false,
"msg": "Unhandled exception while executing module: (0) : Warning as Error: Invalid search path 'System.Collections.DictionaryEntry' specified in 'LIB environment variable' -- 'The system cannot find the path specified. '\n\n(1) : using Microsoft.Win32.SafeHandles;\n"
}
Problems happens with 2.11.6 and 2.11.4 of Ansible core, but not with 2.10 (at least 2.10.9)
I'm wondering if it's a new check in 2.11 or if it's something I should open a bug report about.
EDIT1: changed 'c:' to 'c:\temp' as the win_stat command is long on the former, much faster on the later
I wasn't looking in the right repository for this. The bug is already opened, on ansible.windows collection : https://github.com/ansible-collections/ansible.windows/issues/297
I'm unable to ping the another server. And i have SSH communication also authenticated.
Please find the below error
ansible all -m ping -u ubuntu -i inventory
WARNING]: Unhandled error in Python interpreter discovery for host 10.0.3.128: No JSON object could be decoded
[WARNING]: Unhandled error in Python interpreter discovery for host 10.0.3.53: No JSON object could be decoded
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named zipfile
[WARNING]: Platform linux on host 10.0.3.128 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
10.0.3.128 | FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"module_stderr": "Shared connection to 10.0.3.128 closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1574742993.99-111761674559704/AnsiballZ_ping.py\", line 102, in <module>\r\n _ansiballz_main()\r\n File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1574742993.99-111761674559704/AnsiballZ_ping.py\", line 21, in _ansiballz_main\r\n import zipfile\r\nImportError: No module named zipfile\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named zipfile
[WARNING]: Platform linux on host 10.0.3.53 is using the discovered Python interpreter at /usr/bin/python, but future installation of another Python interpreter could change this. See
https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information.
10.0.3.53 | FAILED! => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false,
"module_stderr": "Shared connection to 10.0.3.53 closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1574742994.0-31022973006547/AnsiballZ_ping.py\", line 102, in <module>\r\n _ansiballz_main()\r\n File \"/home/ubuntu/.ansible/tmp/ansible-tmp-1574742994.0-31022973006547/AnsiballZ_ping.py\", line 21, in _ansiballz_main\r\n import zipfile\r\nImportError: No module named zipfile\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
Prasanna, go to 10.0.3.128 run python, and try to :
import zipfile
It seems like either it wasn't compiled with it or it can't find the library so maybe an environment issue. try it as the ansible user
I have got the similar error and resolved it.
After creating the container I used the following command to install python on it:
apt-get install python-minimal --no-install-recommends
But, when i got the "ImportError: No module named zipfile" error with ansible ping command, I just got into the container (with lxc-attach) and used:
apt-get install python
And then my ansible ping command worked as expected.
Seems like ansible is not able to find python distribution in the client.
The simplest solution is to tell ansible where to find it in ansible.cfg. Just add:
[defaults]
...
interpreter_python = <pyhton path in client>
the python path in the client can be found by running:
which python
or for newer versions (recommended for ansible):
which python3
like so:
in most modern Debian based distributions, python is located at /usr/bin/python3
that makes the final solution:
[defaults]
...
interpreter_python = /usr/bin/python3
I am trying to use ansible to deploy our system. I used expect module in yml file and try using ansible-playbook to run it and got this error:
fatal: [192.168.100.132]: FAILED! => {"changed": false, "failed":
true, "msg": "The pexpect python module is required"}
Then I downloaded the pexpect-4.2.1 package from pypi.python.org and install it by "python setup.py install".
But it doesn't work and error never changed.
What should I do to deal with the error ?
Some code from yml file:
- name: auth root
expect:
command: mysql_secure_installation
responses:
'Enter password for user root:': '{{password.stdout}}'
'New password:': 'dtise123'
'Re-enter new password:': 'dtise123'
'Do you wish to continue with the password provided\?\(Press y\|Y for Yes, any other key for No\) :': 'y'
'Remove anonymous users\? \(Press y\|Y for Yes, any other key for No\) :': 'y'
'Disallow root login remotely\? \(Press y\|Y for Yes, any other key for No\) :': 'y'
'Remove test database and access to it\? \(Press y\|Y for Yes, any other key for No\) :': 'y'
'Reload privilege tables now\? \(Press y\|Y for Yes, any other key for No\) :': 'y'
echo: yes
I downloaded the pexpect-4.2.1.tar.gz from pypi.python.org and did like this:
mv pexpect-4.2.1.tar.gz /usr/local/src/
cd /usr/local/src
tar zxvf pexpect-4.2.1.tar.gz
cd pexpect-4.2.1
python setup.py install
I installed it [pexpect] on the Ansible host. Do I need to install it on each node machine?
Yes, modules are executed on target machines and prerequisites (if they exist) must be installed on them.
I was trying to copy a test file from a Linux control server to a Windows 7 client. my playbook is
- name: Test Copy from Linux to Windows
hosts: Windows
gather_facts: false
tasks:
- name: Copy
copy: src=/tmp/tmp.txt dest=C:\Ansible
And getting this error
failed: [10.8.0.4] => {"failed": true, "md5sum": "c9566265d534d0e3c666ea52daf96cc8", "parsed": false}
invalid output was: The argument 'C:\Users\me.HOMEPC\AppData\Local\Temp\ansible-tmp-1422383762.86-109261083693479\\copy.ps1' to the -File parameter does not exist. Provide the path to an existing '.ps1' file as an argument to the -File parameter.
FATAL: all hosts have already failed -- aborting
Any thoughts? How I can make this work?
There's a small bug in that fork version. Use https://gist.github.com/dmitrydigi/dc4843fca7e69bcca147 with the fix. If you use the mentioned version, then template will always report changed=true.
Looks like the copy module doesn't support for file copy function in Windows and atm, a win_copy module is in the dev phase.
However I have found this VERY useful module which is copy.ps1
https://gist.github.com/tkinz27/fd92ba9af0e0309614ee
And then things got working :-)
Important: You gotta upgrade your Windows (7) Powershell to Version 4.0
I have a simple .pp / puppet file, and I'm getting "Parameter provider failed: Invalid package provider 'pip' at sis.pp:24"
Here's the line 24:
20 package {"numpy":
21 ensure => installed,
22 provider => pip,
23 require => Package["python-setuptools", "python-pip", "python-dev", "build-essential"]
24 }
I checked for syntax errors, there are none.
My guess is that puppet can't find pip, I uninstalled and installed pip again. With apt-get,
here's what i get when i type "whereis pip"
pip: /usr/local/bin/pip /usr/share/man/man1/pip.1.gz
I searched around and found that puppet has a pip module, installed it too.
But still clueless about what the problem is.
When I type "puppet apply sis.pp --debug --verbose"
I get this:
debug: Puppet::Type::Package::ProviderSunfreeware: file pkg-get does not exist
debug: Puppet::Type::Package::ProviderFink: file /sw/bin/fink does not exist
debug: Puppet::Type::Package::ProviderYum: file yum does not exist
debug: Puppet::Type::Package::ProviderRug: file /usr/bin/rug does not exist
debug: Puppet::Type::Package::ProviderAix: file /usr/bin/lslpp does not exist
debug: Puppet::Type::Package::ProviderPorts: file /usr/sbin/pkg_info does not exist
debug: Puppet::Type::Package::ProviderNim: file /usr/sbin/nimclient does not exist
debug: Puppet::Type::Package::ProviderRpm: file rpm does not exist
debug: Puppet::Type::Package::ProviderSun: file /usr/sbin/pkgrm does not exist
debug: Puppet::Type::Package::ProviderPortupgrade: file /usr/sbin/pkg_info does not exist
debug: Puppet::Type::Package::ProviderHpux: file /usr/sbin/swremove does not exist
debug: Puppet::Type::Package::ProviderZypper: file /usr/bin/zypper does not exist
debug: Puppet::Type::Package::ProviderFreebsd: file /usr/sbin/pkg_delete does not exist
debug: Puppet::Type::Package::ProviderUp2date: file /usr/sbin/up2date-nox does not exist
debug: Puppet::Type::Package::ProviderPkg: file /usr/bin/pkg does not exist
debug: Puppet::Type::Package::ProviderPortage: file /usr/bin/eix does not exist
debug: Puppet::Type::Package::ProviderAptrpm: file rpm does not exist
debug: Puppet::Type::Package::ProviderOpenbsd: file pkg_delete does not exist
debug: Puppet::Type::Package::ProviderUrpmi: file urpmq does not exist
Parameter provider failed: Invalid package provider 'pip' at /path/sis.pp:54
Observe the puppet interpreter is pointing to multiple places in the sis.pp file where it couldn't process provider => "pip"
need help. I'm now going to try and find the terminal output code lines in puppet source to see what the problem is. If somebody knows the solution already, help would be appreciated.
I'm on ubuntu.
It appears your installation can't find the pip provider, rather than it not being able to find the pip executable.
I'm guessing the provider you mentioned is this one:
https://github.com/rcrowley/puppet-pip
Couple of things that might not be clear:
The plugin needs to be available on the puppet clients
Just installing the Gem won't do it for you, hence the manual env setting in the README
Probably the easiest approach is to include the puppet-pip provider in your puppet repo as a separate module, and then enable pluginsync, i.e.
[main]
pluginsync = true
More details here http://docs.puppetlabs.com/guides/plugins_in_modules.html
It looks like pip provider is not available in puppet pre 2.7 without downloading an external provider. Are you using 2.7 or higher?