Ansible - Unable to decode JSON from response - ansible

I'm trying to run the command show redundant summary on a cisco Wlan controller (Catalyst 6509-E).
When I use this aireos_command from ansible:
- name: show redundancy summary
aireos_command:
commands: show redundancy summary
register: wlan_output
vars:
ansible_connection: local
I get following error (ignore deprecation warning):
{
"msg": "Unable to decode JSON from response to exec_command({\"command\": \"show redundancy summary\", \"prompt\": null, \"answer\": null}). Received 'None'.",
"rc": 1,
"invocation": {
"module_args": {
"commands": [
"show redundancy summary"
],
"provider": {
"host": null,
"port": null,
"username": null,
"password": null,
"ssh_keyfile": null,
"timeout": null
},
"match": "all",
"retries": 10,
"interval": 1,
"wait_for": null,
"host": null,
"port": null,
"username": null,
"password": null,
"ssh_keyfile": null,
"timeout": null
}
},
"ansible_facts": {
"discovered_interpreter_python": "/usr/bin/python"
},
"deprecations": [
{
"msg": "Distribution rhel 8.6 on host tcehwa should use /usr/libexec/platform-python, but is using /usr/bin/python for backward compatibility with prior Ansible releases. A future Ansible release will default to using the discovered platform python for this host. See https://docs.ansible.com/ansible/2.9/reference_appendices/interpreter_discovery.html for more information",
"version": "2.12"
}
],
"_ansible_no_log": false,
"changed": false
}
Why do i get null as an answer?

Perhaps installing the Python package ansible-pylibssh will help; it seems like the ansible.module_util.connection.Connection class isn't happy with Paramiko and the aireos_command module.

Related

Ansible - SNMP Service on Windows 10 is not appearing

I am installing SNMP service on Windows 10 through ansible. As per ansible output, it is getting installed but not appearing in the services.msc.
Playbook task
tasks:
- name: Install Service
ansible.windows.win_powershell:
script: add-WindowsCapability -Online -Name "SNMP.Client----0.0.1.0"
output
changed: [10.65.150.240] => {
"changed": true,
"debug": [],
"error": [],
"host_err": "",
"host_out": "",
"information": [],
"invocation": {
"module_args": {
"arguments": null,
"chdir": null,
"creates": null,
"depth": 2,
"error_action": "continue",
"executable": null,
"parameters": null,
"removes": null,
"script": "add-WindowsCapability -Online -Name \"SNMP.Client----0.0.1.0\""
}
},
"output": [
{
"LogLevel": {
"String": "WarningsInfo",
"Type": "Microsoft.Dism.Commands.LogLevel",
"Value": 2
},
"LogPath": "C:\\windows\\Logs\\DISM\\dism.log",
"Online": true,
"Path": null,
"RestartNeeded": false,
"ScratchDirectory": null,
"SysDrivePath": null,
"WinPath": null
}
],
"result": {},
"verbose": [],
"warning": []
}
The name of the feature is actually a little different. It should contain the ~ character instead of -.
Change the install command to this:
Add-WindowsCapability -Online -Name "SNMP.Client~~~~0.0.1.0"
Unfortunately, the output from the install seems to be the same whether or not the correct name was used. If you need to confirm it was installed, I suggest checking the state afterward to verify it's "Installed."
PS C:\> Get-WindowsCapability -Online -Name "SNMP.Client~~~~0.0.1.0" | Select State
State
-----
Installed

VirtualBox silent install via Ansible fails?

$ ansible --version
ansible 2.10.8
Per Oracle VM VirtualBox 6.1 Silent Install (How-To Guide), I should be able to install VirtualBox silently like this
C:\temp> VirtualBox-6.1.28-147628-Win.exe --silent --ignore-reboot
and if I run the above command in a Windows command prompt, it succeeds and installs VirtualBox.
Now I do this in Ansible
- name: "Install {{ artifact_filename }}"
win_package:
path: "C:\\temp\\VirtualBox-6.1.28-147628-Win.exe"
arguments: "--silent --ignore-reboot"
state: present
and I get this when I run the playbook with the task.
fatal: [10.227.x.x]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"arguments": "--silent --ignore-reboot",
"chdir": null,
"client_cert": null,
"client_cert_password": null,
"creates_path": null,
"creates_service": null,
"creates_version": null,
"expected_return_code": [
0,
3010
],
"follow_redirects": "safe",
"force_basic_auth": false,
"headers": null,
"http_agent": "ansible-httpget",
"log_path": null,
"maximum_redirection": 50,
"password": null,
"path": "C:\\temp\\VirtualBox-6.1.28-147628-Win.exe",
"product_id": null,
"provider": "auto",
"proxy_password": null,
"proxy_url": null,
"proxy_use_default_credential": false,
"proxy_username": null,
"state": "present",
"url_method": null,
"url_password": null,
"url_timeout": 30,
"url_username": null,
"use_default_credential": false,
"use_proxy": true,
"username": null,
"validate_certs": true,
"wait_for_children": false
}
},
"msg": "unexpected rc from 'C:\\temp\\VirtualBox-6.1.28-147628-Win.exe --silent --ignore-reboot': see rc, stdout, and stderr for more details",
"rc": 1,
"reboot_required": false,
"stderr": "",
"stderr_lines": [],
"stdout": "",
"stdout_lines": []
}
What am I missing? TIA.
I RTFM'd the win_package documentation. It says regarding the arguments option
arguments This is only used for the msi, msp, and registry providers.
So I do this instead
- name: "Install VirtualBox"
win_command: "C:\\temp\\VirtualBox-6.1.28-147628-Win.exe --silent --ignore-reboot"
If anyone has a better answer I'm all eyes.

Is it possible to combine with_dict with with_items?

I have an output of a playbook and I want to debug a message based on a condition of the output. I need the key and value pairs of the item to match a when statement then I will print out the actual data.
ok: [pynet-sw5] => {
"loop_iterate": {
"changed": false,
"msg": "All items completed",
"results": [
{
"_ansible_ignore_errors": null,
"_ansible_item_label": "1.1.1.1",
"_ansible_item_result": true,
"_ansible_no_log": false,
"_ansible_parsed": true,
"changed": false,
"failed": false,
"invocation": {
"module_args": {
"count": null,
"destination": "1.1.1.1",
"dev_os": "eos",
"hostname": "arista5.twb-tech.com",
"optional_args": null,
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"ping_timeout": null,
"provider": {
"dev_os": "eos",
"hostname": "arista5.twb-tech.com",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"timeout": 60,
"username": "xxx"
},
"size": null,
"source": null,
"timeout": 60,
"ttl": null,
"username": "pyclass",
"vrf": null
}
},
"item": "1.1.1.1",
"results": {
"success": {
"packet_loss": 0,
"probes_sent": 5,
When I put the below statement it returns with item is not defined error.
- debug:
msg: "{{item[1].item}} is pingable from {{ansible_host}} with {{item[1].results.success.packet_loss}} out of 5 packets"
when: "item[0].key == 'packet_loss'"
with_sublements:
- "{{loop_iterate.results.results.success}}"
- "{{loop_iterate.results}}"
so is there a way of combining with_dict with with_items ? I want to use
- "{{loop_iterate.results.results.success}}" as with_dict iteration while using - "{{loop_iterate.results}}" as with_items

Proxmoxer required for this module

I keep getting this error when try create ProxMox containers using Ansible. Has anyone know how to fix this? Im trying to create Proxmox VE cluster containers. Uses LXD containers.
Here is my playbook
- hosts: proxmox
user: root
tasks:
- name: Test container
proxmox:
vmid: 777
node: 'pve'
api_user: 'root#pam'
api_password: 'admin'
api_host: 'node1'
password: '123456'
hostname: 'example.org'
ostemplate: 'local:vztmpl/ubuntu-16.04-standard_16.04-1_amd64.tar.gz'
Here is complete Ansible debug report
The full traceback is:
File "/tmp/ansible_p2azl7/ansible_module_proxmox.py", line 325, in <module>
from proxmoxer import ProxmoxAPI
fatal: [proxmox]: FAILED! => {
"changed": false,
"failed": true,
"invocation": {
"module_args": {
"api_host": "node1",
"api_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"api_user": "root#pam",
"cores": 1,
"cpus": 1,
"cpuunits": 1000,
"disk": "3",
"force": false,
"hostname": "example.org",
"ip_address": null,
"memory": 512,
"mounts": null,
"nameserver": null,
"netif": null,
"node": "pve",
"onboot": false,
"ostemplate": "local:vztmpl/ubuntu-16.04-standard_16.04-1_amd64.tar.gz",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"pool": null,
"pubkey": null,
"searchdomain": null,
"state": "present",
"storage": "local",
"swap": 0,
"timeout": 30,
"unprivileged": false,
"validate_certs": false,
"vmid": "777"
}
},
"msg": "proxmoxer required for this module"
}
Any help is appreciated and thanks in advance.
Install proxmoxer on proxmox machine.
Or otherwise explain, what is your expectation for trying to run it without the library. You might be running it on a different target than you intended.

How to create a directory with particular SE Linux context on it

Here is what I have:
- name: Create directories that will be used as persistent volumes
become: yes
become_method: sudo
file:
path: /tmp/pv-{{ item }}
state: directory
mode: "g=rwx"
group: "root"
selevel: _default
seuser: _default
serole: _default
setype: svirt_sandbox_file_t
with_items:
- cassandra
- services
The two directories are correctly created, group a rights are ok. But the SE Linux context is wrong.
$ ll -dZ /tmp/pv-cassandra
drwxrwxr-x. 2 jkremser root unconfined_u:object_r:user_tmp_t:s0 40 Mar 9 15:19 /tmp/pv-cassandra
This is the part of the debugging output:
ok: [localhost] => (item=cassandra) => {
"changed": false,
"diff": {
"after": {
"path": "/tmp/pv-cassandra"
},
"before": {
"path": "/tmp/pv-cassandra"
}
},
"gid": 0,
"group": "root",
"invocation": {
"module_args": {
"backup": null,
"content": null,
"delimiter": null,
"diff_peek": null,
"directory_mode": null,
"follow": false,
"force": false,
"group": "root",
"mode": "g=rwx",
"original_basename": null,
"owner": null,
"path": "/tmp/pv-cassandra",
"recurse": false,
"regexp": null,
"remote_src": null,
"selevel": "_default",
"serole": "_default",
"setype": "svirt_sandbox_file_t",
"seuser": "_default",
"src": null,
"state": "directory",
"unsafe_writes": null,
"validate": null
},
"module_name": "file"
},
"item": "cassandra",
"mode": "0775",
"owner": "root",
"path": "/tmp/pv-cassandra",
"size": 80,
"state": "directory",
"uid": 0
}
What am I doing wrong? My OS is Fedora 25.
If I use the copy module, instead of the file, that has almost the same parameters, it throws this error:
Aborting, target uses selinux but python bindings (libselinux-python) aren't installed
After installing the libselinux-python package, it works! So it looks like the file module silently swallows the error and does what it can do :( I can't depend on the fact that user has the libselinux-python package installed.
I'll probably call the chcon myself as a shell command or add the package as a prerequisite:
- name: Install the libselinux-python package
package:
name: libselinux-python
state: present

Resources