I'm running into an issue where I'm not sure what is cause, here is the setup:
Following the Ansible win_service doc
Debian GNU/Linux buster/sid
ansible 2.7.5
config file = /home/ansible/ansibleGalaxy/ansible.cfg
configured module search path = [u'/home/ansible/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.15+ (default, Nov 28 2018, 16:27:22) [GCC 8.2.0]
Playbook:
- name: Update Dalet Installer service
win_service:
name: DaletInstallerService
username: .\Administrator
password: toto
start_mode: auto
state: started
Basically I want to update the credential of the service on the target machine.
And whatever setting i'm getting this error message:
fatal: [192.168.56.103]: FAILED! => {
"can_pause_and_continue": false,
"changed": false,
"depended_by": [],
"dependencies": [
"Afd",
"Tcpip"
],
"description": "DaletInstallerService",
"desktop_interact": false,
"display_name": "DaletInstallerService",
"exists": true,
"msg": "Service 'DaletInstallerService (DaletInstallerService)' cannot be started due to the following error: Cannot start service DaletInstallerService on computer '.'.",
"name": "DaletInstallerService",
"path": "'C:\\Program Files (x86)\\DALET\\DaletInstaller\\DaletInstallerService.prunsrv.exe' //RS//DaletInstallerService",
"start_mode": "auto",
"state": "stopped",
"username": ".\\Administrator"
}
ERROR! Unexpected Exception, this is probably a bug: 'ascii' codec can't encode character u'\xa0' in position 29: ordinal not in range(128)
the full traceback was:
Traceback (most recent call last):
File "/usr/bin/ansible-playbook", line 118, in <module>
exit_code = cli.run()
File "/usr/lib/python2.7/dist-packages/ansible/cli/playbook.py", line 122, in run
results = pbex.run()
File "/usr/lib/python2.7/dist-packages/ansible/executor/playbook_executor.py", line 156, in run
result = self._tqm.run(play=play)
File "/usr/lib/python2.7/dist-packages/ansible/executor/task_queue_manager.py", line 291, in run
play_return = strategy.run(iterator, play_context)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/strategy/linear.py", line 325, in run
results += self._wait_on_pending_results(iterator)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/strategy/__init__.py", line 712, in _wait_on_pending_results
results = self._process_pending_results(iterator)
File "/usr/lib/python2.7/dist-packages/ansible/plugins/strategy/__init__.py", line 135, in inner
dbg.cmdloop()
File "/usr/lib/python2.7/dist-packages/ansible/plugins/strategy/__init__.py", line 1166, in cmdloop
cmd.Cmd.cmdloop(self)
File "/usr/lib/python2.7/cmd.py", line 130, in cmdloop
line = raw_input(self.prompt)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 29: ordinal not in range(128)
Still looking for a workaround or a fix, but any input would be welcome to understand the root cause.
Matth
Related
Seeing some issue with netmiko KEY authentication with N7K.
Python 3.8.10, netmiko 4.1.2.
Firstly tried on N9K without any issue, command can be sent after get the connection.
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from netmiko import ConnectHandler
>>> n9k = {"device_type": "cisco_nxos", "host": "10.1.1.10", "username": "admin", "use_keys": True,"key_file":"~/.ssh/id_rsa", "passphrase": "Cisco123"}
>>> target_con = ConnectHandler(**n9k)
Hit the issue when trying the connection to a N7K switch.
>>> n7k = {"device_type": "cisco_nxos", "host": "10.1.1.20", "username": "admin", "use_keys": True,"key_file":"~/.ssh/id_rsa", "passphrase": "Cisco123"}
>>> target_con = ConnectHandler(**n7k)
Traceback (most recent call last):
File "/home/admin/netmiko_test/lib/python3.8/site-packages/netmiko/base_connection.py", line 1046, in establish_connection
self.remote_conn_pre.connect(**ssh_connect_params)
File "/home/admin/netmiko_test/lib/python3.8/site-packages/paramiko/client.py", line 435, in connect
self._auth(
File "/home/admin/netmiko_test/lib/python3.8/site-packages/paramiko/client.py", line 771, in _auth
raise saved_exception
File "/home/admin/netmiko_test/lib/python3.8/site-packages/paramiko/client.py", line 747, in _auth
self._transport.auth_publickey(username, key)
File "/home/admin/netmiko_test/lib/python3.8/site-packages/paramiko/transport.py", line 1635, in auth_publickey
return self.auth_handler.wait_for_response(my_event)
File "/home/admin/netmiko_test/lib/python3.8/site-packages/paramiko/auth_handler.py", line 259, in wait_for_response
raise e
paramiko.ssh_exception.AuthenticationException: Authentication failed.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/admin/netmiko_test/lib/python3.8/site-packages/netmiko/ssh_dispatcher.py", line 365, in ConnectHandler
return ConnectionClass(*args, **kwargs)
File "/home/admin/netmiko_test/lib/python3.8/site-packages/netmiko/base_connection.py", line 439, in __init__
self._open()
File "/home/admin/netmiko_test/lib/python3.8/site-packages/netmiko/base_connection.py", line 444, in _open
self.establish_connection()
File "/home/admin/netmiko_test/lib/python3.8/site-packages/netmiko/base_connection.py", line 1083, in establish_connection
raise NetmikoAuthenticationException(msg)
netmiko.exceptions.NetmikoAuthenticationException: Authentication to device failed.
Common causes of this problem are:
1. Invalid username and password
2. Incorrect SSH-key file
3. Connecting to the wrong device
Device settings: cisco_nxos 10.1.1.20:22
Authentication failed.
>>>
The username and ssh key have been validated. All work well if using username/password instead.
Any advice would be appreciated.
Thanks!
Found the issue when studying another similar paramiko problem.
The N9K node I tested against with uses openssh 8.3, thus it is rsa-sha2-256.
The N7K node uses openssh5.9 which is ssh-sha1.
That makes a difference as netmiko seems don't like ssh-sha1 by default.
Adding disabled_algorithms = {'pubkeys': ['rsa-sha2-256', 'rsa-sha2-512']} to ConnectHandler fixed the issue.
I try to connect remotely to mongodb server from pycharm(with RDP).
this is thefunction that i run:
cluster = MongoClient("mongodb://admin:Passw0rd!#147.234.32.246:27017/NEG")
db = cluster["NEG"]
for word in Setting.dictionary_global.keys():
if word in db.list_collection_names():
collection = db[word]
for file in Setting.dictionary_global[word].keys():
if collection.find({"url":Setting.dictionary_global[word][file].url}):
continue
num_of_appearance = len(Setting.dictionary_global[word][file].indexes.get(word))
post = {"url": file, "title": Setting.dictionary_global[word][file].title,
"description": Setting.dictionary_global[word][file].description,"word in page": Setting.dictionary_global[word][file].indexes,"appearance": num_of_appearance, "date modified": Setting.dictionary_global[word][file].time}
collection.insert_one(post)
else:
collection = db.create_collection(word)
for file in Setting.dictionary_global[word].keys():
#print(Setting.dictionary_global)
num_of_appearance = len(Setting.dictionary_global[word][file].indexes.get(word))
post = {"url": file, "title": Setting.dictionary_global[word][file].title,
"description": Setting.dictionary_global[word][file].description,"word in page": Setting.dictionary_global[word][file].indexes, "appearance": num_of_appearance, "date modified":Setting.dictionary_global[word][file].time}
collection.insert_one(post)
and i get this error:
'''
Traceback (most recent call last):
File "C:/Users/edend/PycharmProjects/pythonProject11/main.py", line 118, in
crawler.start()
File "C:/Users/edend/PycharmProjects/pythonProject11/main.py", line 110, in start
insertDB()
File "C:\Users\edend\PycharmProjects\pythonProject11\DB.py", line 10, in insertDB
if word in db.list_collection_names():
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\database.py", line 863, in list_collection_names
for result in self.list_collections(session=session, **kwargs)]
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\database.py", line 825, in list_collections
return self.__client._retryable_read(
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\mongo_client.py", line 1460, in _retryable_read
server = self._select_server(
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\mongo_client.py", line 1278, in _select_server
server = topology.select_server(server_selector)
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\topology.py", line 241, in select_server
return random.choice(self.select_servers(selector,
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\topology.py", line 199, in select_servers
server_descriptions = self._select_servers_loop(
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\topology.py", line 215, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: 147.234.32.246:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 5ff3d15a2dcaa1e4fb3db4cd, topology_type: Single, servers: [<ServerDescription ('147.234.32.246', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('147.234.32.246:27017: timed out')>]>
'''
please help me im stuck and iv'e try everything
thank you in advance!!
Common causes:
MongoDB server is not running
MongoDB server is running on a different port
No connectivity between client and server (can you ping)
mongod.conf is configure to only allow local connections by default (set bind_ip_all?)
I tried to write an Ansible module. My module is buggy. When I run it from a playbook I get the following unreadable output:
$ ansible-playbook lacp.yml
PLAY [xxxxxxxx] ****************************************************************
TASK [Test that my module works] ***********************************************
fatal: [xxxxxxxx]: FAILED! => {"changed": false, "failed": true, "module_stderr": "couldn't set locale correctly\ncouldn't set locale correctly\ncouldn't set locale correctly\nTraceback (most recent call last):\n File \"/tmp/ansible_vHkWq8/ansible_module_lacp.py\", line 27, in <module>\n main()\n File \"/tmp/ansible_vHkWq8/ansible_module_lacp.py\", line 14, in main\n m = re.match('^key: ([0-9]+) ', dladm.readline())\nAttributeError: 'Popen' object has no attribute 'readline'\ndladm: insufficient privileges\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}
NO MORE HOSTS LEFT *************************************************************
[WARNING]: Could not create retry file 'lacp.retry'. [Errno 2] No such file or directory: ''
PLAY RECAP *********************************************************************
xxxxxxxx : ok=0 changed=0 unreachable=0 failed=1
How to stop Ansible quoting error messages with JSON? Or is there another way to debug Ansible modules?
How to stop Ansible quoting error messages with JSON?
You can use human_log.py plugin to force Ansible to interpret and print newline characters in its output.
You put the file into /path/to/callback_plugins/ directory and add the following to the ansible.cfg:
[defaults]
callback_plugins = /path/to/callback_plugins/
The detailed instructions are in the Human-Readable Ansible Playbook Log Output Using Callback Plugin blog post.
You can look into this and this callback plugins (for Ansible 2.x).
You will need to modify them a bit, because they don't convert module_stderr out of the box.
Also you may want to execute playbook with ANSIBLE_KEEP_REMOTE_FILES=1, then ssh to the remote box and debug your module in-place, then save to ansible library.
Debugging Ansible modules will quickly become next to impossible and very, very time consuming without following the recommended approach.
The recommended approach is to build your Ansible stuff using very small steps. That way you can more easily guess what is wrong as you add stuff to what you know and have verified to work.
So when you state that the module is buggy, you have gone to far. You will be searching for a needle in the haystack that Ansible without question is.
Refactoring is not really a practical option. You basically start fresh, recreating your code step by step.
I hope you noticed that Ansible doesn't even bother to format error output in a human readable way. In a way on error Ansible outputs the same message: something went wrong.
Let's say I have this Ansible task
- name: Mymodule
mymodule:
something: "something"
My module also is simple enough
#!/usr/bin/python
from ansible.module_utils.basic import *
def somefunction(data):
has_changed = False
meta = { "something": "something"}
return (has_changed, meta)
def main():
fields = {
"something": {"required": True, "type": "str"},
"state": {
"default": "perform",
"choices": ["perform"],
"type": "str"
},
}
choice_map = {
"perform2": somefunction,
}
module = AnsibleModule(argument_spec=fields)
has_changed, result = choice_map.get(module.params['state'])(module.params)
module.exit_json(changed=has_changed, meta=result)
if __name__ == '__main__':
main()
Ansible will produce the following error message
TASK [backup : Mymodule]
******************************************************* fatal: [myapp]: FAILED! => {"changed": false, "module_stderr": "Shared
connection to 127.0.0.1 closed.\r\n", "module_stdout": "Traceback
(most recent call last):\r\n File
\"/home/vagrant/.ansible/tmp/ansible-tmp-1570188887.99-191548982937437/AnsiballZ_mymodule.py\",
line 114, in \r\n _ansiballz_main()\r\n File
\"/home/vagrant/.ansible/tmp/ansible-tmp-1570188887.99-191548982937437/AnsiballZ_mymodule.py\",
line 106, in _ansiballz_main\r\n invoke_module(zipped_mod,
temp_path, ANSIBALLZ_PARAMS)\r\n File
\"/home/vagrant/.ansible/tmp/ansible-tmp-1570188887.99-191548982937437/AnsiballZ_mymodule.py\",
line 49, in invoke_module\r\n imp.load_module('main', mod,
module, MOD_DESC)\r\n File
\"/tmp/ansible_mymodule_payload_XTaVPp/main.py\", line 29, in
\r\n File
\"/tmp/ansible_mymodule_payload_XTaVPp/main.py\", line 25, in
main\r\nTypeError: 'NoneType' object is not callable\r\n", "msg":
"MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
The "message" we should focus on is
TypeError: 'NoneType' object is not callable
It is caused by the wrong action perform2. It should be perform. A simple typo.
choice_map = {
"perform2": somefunction,
}
The typo is in module file mymodule.py on line 21. The files and lines 114, 106, 49, 29, 25 might be useful in someway but how these files are useful is not clear at all.
This is just a very simple example to illustrate the point of the haystack. Ansible does not format the error message in human readable way. Reporting on the problem file and line number is also not an exact science. And the error message is not useful. The error message should be that my choice_map is referencing a non-existing action. It could list the available choices.
IMHO this is a common problem with Ansible. A typing mistake can take a hour to fix.
The only way to workaround this limitation is to build up provision step by step. Baby steps.
I am following the sample code and instructions given here. I created Parse account and an app in it.
I also installed Parse using
curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash in MAC OS.
Now when I run parse deploy command from terminal, I get the following error stack:
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/local/bin/parse/__main__.py", line 6, in <module>
File "/usr/local/bin/parse/main.py", line 696, in main
File "/usr/local/bin/parse/main.py", line 202, in handle_deploy
File "/usr/local/bin/parse/parse.py", line 110, in __init__
File "/usr/local/bin/parse/parse.py", line 118, in load_state
File "/usr/local/bin/parse/config_handler.py", line 125, in get_keys_for_app
File "/usr/local/bin/parse/config_handler.py", line 100, in get_info_for_apps
File "/usr/local/bin/parse/config_handler.py", line 112, in get_app_info_for_file
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 290, in load
**kw)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 381, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 3 column 9 (char 32)
Where am I getting wrong? How do I solve this?
once you have the project set up:
Ensure your global.json file is well-configured. For example:
{
"applications": {
"YOUR_APP_NAME": {
"applicationId": "YOUR_APP_ID",
"masterKey": "YOUR_MASTER_KEY"
},
"ANOTHER_APP_NAME": {
"applicationId": "ANOTHER_APP_ID",
"masterKey": "ANOTHER_MASTER_KEY"
},
"_default": {
"link": "YOUR_APP_NAME"
}
},
"global": {
"parseVersion": "1.2.18"
}
}
So from terminal, go in the folder at the same level of "cloud","config","public","test"
and run the command "parse deploy" that will call the deploy for the default app "YOUR_APP_NAME" ( change it to "ANOTHER_APP_NAME" if you have other app at which send that cloud code, for example a develop app and production app).
Ensure to have the "main.js" file in the "cloud" folder, and a sample index.html file in the "public" folder
If you have parse installed properly , you should be able to work with it.
Hope it helps
I want to provide my vagrant box with cuisine, I followed this tutorial but when I try to provide my box with vagrant provision command I get the next error:
[default] Running provisioner: fabric...
[127.0.0.1] Executing task 'provide'
[127.0.0.1] sudo: apt-get update
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/fabric/main.py", line 743, in main
*args, **kwargs
File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 368, in execute
multiprocessing
File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 264, in _execute
return task.run(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/fabric/tasks.py", line 171, in run
return self.wrapped(*args, **kwargs)
File "/home/user/projects/volaris2013/provision.py", line 10, in provide
prepare_os()
File "/home/user/projects/volaris2013/provision.py", line 32, in prepare_os
sudo('apt-get update')
File "/usr/local/lib/python2.7/dist-packages/fabric/network.py", line 578, in host_prompting_wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/fabric/operations.py", line 1095, in sudo
stderr=stderr, timeout=timeout, shell_escape=shell_escape,
File "/usr/local/lib/python2.7/dist-packages/fabric/operations.py", line 909, in _run_command
channel=default_channel(), command=wrapped_command, pty=pty,
File "/usr/local/lib/python2.7/dist-packages/fabric/state.py", line 388, in default_channel
chan = _open_session()
File "/usr/local/lib/python2.7/dist-packages/fabric/state.py", line 380, in _open_session
return connections[env.host_string].get_transport().open_session()
File "/usr/local/lib/python2.7/dist-packages/fabric/network.py", line 118, in __getitem__
self.connect(key)
File "/usr/local/lib/python2.7/dist-packages/fabric/network.py", line 110, in connect
self[key] = connect(user, host, port, sock)
File "/usr/local/lib/python2.7/dist-packages/fabric/network.py", line 392, in connect
sock=sock
File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 342, in connect
self._auth(username, password, pkey, key_filenames, allow_agent, look_for_keys)
File "/usr/local/lib/python2.7/dist-packages/paramiko/client.py", line 462, in _auth
key = pkey_class.from_private_key_file(key_filename, password)
File "/usr/local/lib/python2.7/dist-packages/paramiko/pkey.py", line 198, in from_private_key_file
key = cls(filename=filename, password=password)
File "/usr/local/lib/python2.7/dist-packages/paramiko/rsakey.py", line 51, in __init__
self._from_private_key_file(filename, password)
File "/usr/local/lib/python2.7/dist-packages/paramiko/rsakey.py", line 163, in _from_private_key_file
data = self._read_private_key_file('RSA', filename, password)
File "/usr/local/lib/python2.7/dist-packages/paramiko/pkey.py", line 279, in _read_private_key_file
f = open(filename, 'r')
IOError: [Errno 2] No such file or directory: '[/home/user/.vagrant.d/insecure_private_key]'
I think that the error are in the brackets arround the filename, but I don't know how to solve this, I had a similar error in the past, but in fabric tasks, and I solved the problem in my env task.
The versions of packages:
Vagrant 1.4.2
Fabric==1.8.0
cuisine==0.6.5
paramiko==1.12.0
VirtualBox 4.3.9
Vagrant (as of 1.4.0) changed to returning the private_key to use from a string to an array. The vagrant-fabric plugin naively assumes it's getting a string and uses #{private_key} directly in its command, which gets written out with the wrapping square brackets.
Here's a fix for lib/vagrant-fabric/provisioner.rb:
private_key = ssh_info[:private_key_path]
# After https://github.com/mitchellh/vagrant/pull/907 (Vagrant 1.4.0+),
# private_key_path is an array.
if ! private_key.kind_of?(Array)
private_key = [private_key]
end
private_key_option = private_key.map { |k| '-i ' + k }.join(' ')
if config.remote == false
system "#{config.fabric_path} -f #{config.fabfile_path} " +
"#{private_key_option} --user=#{user} --hosts=#{host} " +
"--port=#{port} #{config.tasks.join(' ')}"
else
Update: Added pull request: https://github.com/wutali/vagrant-fabric/pull/6