Ansible to Proxmox returning 500 error - ansible

I am trying to use Ansible to provision some VMs on my newly set up Proxmox VE. I have installed proxmoxer and request with PIP on both my local Mac and Proxmox VE (Python 2 on Proxmox and Python 3 locally). I use Ansible 2.4.3.0, Proxmox version: 5.1-41.
I do have a vm with the id of 100, which was created from a Debian template, the vm is located on local-lvm (pve).
My full playbook can be found at: https://github.com/atwright147/ansible-contact-book-proxmox-provisioner, the specific task is pasted below:
---
- proxmox_kvm:
api_user: root#pam
api_password: REDACTED
api_host: pve
vmid: 100
state: current
When running this script via: ansible-playbook -vvv --connection=local -i hosts site.yml I get the following error:
The full traceback is:
File "/tmp/ansible_TDEJsZ/ansible_module_proxmox_kvm.py", line 1227, in main
current = getattr(proxmox.nodes(vm[0]['node']), VZ_TYPE)(vmid).status.current.get()['status']
File "/usr/local/lib/python2.7/dist-packages/proxmoxer/core.py", line 84, in get
return self(args)._request("GET", params=params)
File "/usr/local/lib/python2.7/dist-packages/proxmoxer/core.py", line 79, in _request
resp.content))
fatal: [192.168.0.22]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"acpi": true,
"agent": null,
"api_host": "pve",
"api_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"api_user": "root#pam",
"args": null,
"autostart": false,
"balloon": 0,
"bios": null,
"boot": "cnd",
"bootdisk": null,
"clone": null,
"cores": 1,
"cpu": "kvm64",
"cpulimit": null,
"cpuunits": 1000,
"delete": null,
"description": null,
"digest": null,
"force": null,
"format": "qcow2",
"freeze": null,
"full": true,
"hostpci": null,
"hotplug": null,
"hugepages": null,
"ide": null,
"keyboard": null,
"kvm": true,
"localtime": null,
"lock": null,
"machine": null,
"memory": 512,
"migrate_downtime": null,
"migrate_speed": null,
"name": null,
"net": null,
"newid": null,
"node": null,
"numa": null,
"numa_enabled": null,
"onboot": true,
"ostype": "l26",
"parallel": null,
"pool": null,
"protection": null,
"reboot": null,
"revert": null,
"sata": null,
"scsi": null,
"scsihw": null,
"serial": null,
"shares": null,
"skiplock": null,
"smbios": null,
"snapname": null,
"sockets": 1,
"startdate": null,
"startup": null,
"state": "current",
"storage": null,
"tablet": false,
"target": null,
"tdf": null,
"template": false,
"timeout": 30,
"update": false,
"validate_certs": false,
"vcpus": null,
"vga": "std",
"virtio": null,
"vmid": 100,
"watchdog": null
}
},
"msg": "Unable to get vm None with vmid = 100 status: 500 Internal Server Error: {\"data\":null}"
}
Ansible info:
ansible 2.4.3.0
config file = /Users/andy/Development/proxmox-playbooks/contact-book/ansible.cfg
configured module search path = ['/Users/andy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
ansible python module location = /usr/local/lib/python3.6/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.6.4 (default, Jan 25 2018, 18:48:20) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.38)]
What am I doing wrong?

It turned out that I was making several mistakes here.
I should have been using the proxmox module rather than proxmox_kvm
I needed to use the storage param to set up the container in local-lvm e.g. storage: local-lvm
My final, working task looks like this:
- name: "Create a Linux Container (LXC)"
proxmox:
node: pve
api_user: root#pam
api_password: proxmox_password
api_host: pve
password: vm_password
hostname: vm.hostname.local
ostemplate: "local:vztmpl/ubuntu-16.04-standard_16.04-1_amd64.tar.gz"
storage: local-lvm
cores: 2
state: present

Related

Ansible - Unable to decode JSON from response

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.

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.

maven_artifact comman of ansible is not working in Rundeck

Objective:
Download the artifact jar from nexus to a Target server. I have already tried an attempt to download the jar via URL and not via maven_artifact, which was successful anyway. But wanted to try with maven_artifact command
Code in playbook:
---
- name: TestOfMavenArtifactCommand
hosts: Target_Server_Where_the_Jar_needs_to_be_downloaded
tasks:
- maven_artifact:
group_id: ab.cdef.group
artifact_id: artifact_name
repository_url: 'https://nexusUrl/repository/maven-snapshots'
dest: /folder/artifact_name.jar
username: user
state: present
mode: 0755
When I run the Rundeck job, it fails. The error is like:
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /bin/ansible-playbook
python version = 2.7.5 (default, Jun 11 2019, 12:19:05) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]
Using /etc/ansible/ansible.cfg as config file
Parsed /var/lib/rundeck/work/zxcv-folder-services/scpr-inventory_dev/dev/hosts.yml inventory source with ini plugin
[WARNING]: Ignoring invalid attribute: username
[WARNING]: Ignoring invalid attribute: artifact_id
[WARNING]: Ignoring invalid attribute: dest
[WARNING]: Ignoring invalid attribute: state
[WARNING]: Ignoring invalid attribute: mode
[WARNING]: Ignoring invalid attribute: repository_url
[WARNING]: Ignoring invalid attribute: group_id
PLAYBOOK: main.yml *************************************************************
1 plays in main.yml
fatal: [server00.companyxxx.dev ]: FAILED! => {
"changed": false,
"invocation": {
"module_args": {
"artifact_id": null,
"attributes": null,
"backup": null,
"classifier": "",
"content": null,
"delimiter": null,
"dest": null,
"directory_mode": null,
"extension": "jar",
"follow": false,
"force": null,
"group": null,
"group_id": null,
"keep_name": false,
"mode": null,
"owner": null,
"password": null,
"regexp": null,
"remote_src": null,
"repository_url": null,
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"state": "devsent",
"timeout": 10,
"unsafe_writes": null,
"username": null,
"validate_certs": true,
"version": "latest"
}
},
"msg": "group_id must be set"
}
to retry, use: --limit #/var/lib/rundeck/work/abcd-batch-services/scpr-servers-operations_dev/deploy-servers/tasks/main.retry
Followed the reference of this:
https://docs.ansible.com/ansible/latest/modules/maven_artifact_module.html
This appears to be just an indentation error. Try:
tasks:
- maven_artifact:
group_id: ab.cdef.group
artifact_id: artifact_name
repository_url: 'https://nexusUrl/repository/maven-snapshots'
dest: /folder/artifact_name.jar
username: user
state: present
mode: 0755

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