How fix ValueError: too many values to unpack in Ansible? - pip

I have a simple task.
- name: Install executor package
apt:
name: '{{ item }}'
state: present
with_items:
- python-dev
- python-pip
- python-setuptools
- pip:
name: pipenv
He worked. But making a check, I discovered such a mistake.
TASK [pip] ********************************************************************************
fatal: []: FAILED! => {"changed": false, "failed": true, "module_stderr": "Shared connection to closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/tmp/ansible_WJSCVE/ansible_module_pip.py\", line 601, in \r\n main()\r\n File \"/tmp/ansible_WJSCVE/ansible_module_pip.py\", line 561, in main\r\n is_present = _is_present(pkg, version, pkg_list, pkg_cmd)\r\n File \"/tmp/ansible_WJSCVE/ansible_module_pip.py\", line 283, in _is_present\r\n pkg_name, pkg_version = pkg.split(' ')\r\nValueError: too many values to unpack\r\n", "msg": "MODULE FAILURE", "rc": 0}
I can not understand what the problem is.

Related

ansible error when use unarchive module on local system

Pls. Help
I`m have this playbook:
---
- name: Install service
hosts: some_host
vars:
app: "{{ app_name }}-{{ tag }}.war"
app_folder: "{{ client_dir }}/{{ app_name }}"
tasks:
- name: Unpack archive Java
unarchive:
src={{ java_distrib }}
dest={{ app_folder }}
creates="{{ app_folder }}/{{ java_home }}"
mode=0555
all work fine when i install on remote host.
But when hosts is same machine from i run ansible-playbook i got this error:
TASK [Unpack archive Java] *********************************************************************************************************
fatal: [10.2.9.6]: FAILED! => {"changed": false, "module_stderr": "Shared connection to 10.2.9.6 closed.\r\n", "module_stdout": "Traceback (most recent call last):\r\n File \"/home/stend/.ansible/tmp/ansible-tmp-1586175452.58-42679814338845/AnsiballZ_unarchive.py\", line 114, in <module>\r\n _ansiballz_main()\r\n File \"/home/stend/.ansible/tmp/ansible-tmp-1586175452.58-42679814338845/AnsiballZ_unarchive.py\", line 106, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/home/stend/.ansible/tmp/ansible-tmp-1586175452.58-42679814338845/AnsiballZ_unarchive.py\", line 49, in invoke_module\r\n imp.load_module('__main__', mod, module, MOD_DESC)\r\n File \"/tmp/ansible_unarchive_payload_f_poEj/__main__.py\", line 157, in <module>\r\n File \"/tmp/ansible_unarchive_payload_f_poEj/ansible_unarchive_payload.zip/ansible/module_utils/urls.py\", line 402, in <module>\r\nAttributeError: 'module' object has no attribute 'HTTPSConnection'\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}
and im not understand whats going on. Why connection closed? im try unarchive to local machine. Where i`m wrong? Pls help !
Problem solved, i`m re install python and library libssl1.1

How to fix the error 'module' object has no attribute 'UnexpectedResponse' in Ansible playbook

Here is the playbook for your reference:
---
- name: Closing notes
hosts: XXXX
gather_facts: yes
tasks:
- name: Modify a change request
snow_record:
state: present
table: change_request
username: admin
password: XXXXX
instance: XXXXX
number: XXXXX
data:
state: -3
register: incident
- debug:
var: incident.record.state
Output:
fatal: [XXXXXXX]: FAILED! => {
"changed": false,
"module_stderr": "Shared connection to XXXXXXX closed.\r\n",
"module_stdout": "Traceback (most recent call last):\r\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1577091421.74-160409156883610/AnsiballZ_snow_record.py\", line 114, in \r\n _ansiballz_main()\r\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1577091421.74-160409156883610/AnsiballZ_snow_record.py\", line 106, in _ansiballz_main\r\n invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\r\n File \"/home/ansible/.ansible/tmp/ansible-tmp-1577091421.74-160409156883610/AnsiballZ_snow_record.py\", line 49, in invoke_module\r\n imp.load_module('main', mod, module, MOD_DESC)\r\n File \"/tmp/ansible_snow_record_payload_qHs01F/main.py\", line 334, in \r\n File \"/tmp/ansible_snow_record_payload_qHs01F/main.py\", line 330, in main\r\n File \"/tmp/ansible_snow_record_payload_qHs01F/main.py\", line 319, in run_module\r\nAttributeError: 'module' object has no attribute 'UnexpectedResponse'\r\n",
"msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
"rc": 1
}
需要指定python的环境为 python3,就可以解决
You need to make the Python environment as Python 3, you can solve this problem
eg
[all:vars]
ansible_python_interpreter=/usr/bin/python3

Ansible complains that it cannot find VMware VM when trying to provision a new virtual machine based on a template

This is the error message:
TASK [vsphere_guest] ***********************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: pysphere.resources.vi_exception.VIException: [Object Not Found]: Could not find a VM named 'templatename'
fatal: [localhost]: FAILED! => {"changed": false, "failed": true, "module_stderr": "Traceback (most recent call last):\n File \"/var/folders/5_/zznkc3cs38v1wscsgmsdcc1w0000gn/T/ansible_Z0ldZx/ansible_module_vsphere_guest.py\", line 1879, in \n main()\n File \"/var/folders/5_/zznkc3cs38v1wscsgmsdcc1w0000gn/T/ansible_Z0ldZx/ansible_module_vsphere_guest.py\", line 1836, in main\n vm_extra_config=vm_extra_config\n File \"/var/folders/5_/zznkc3cs38v1wscsgmsdcc1w0000gn/T/ansible_Z0ldZx/ansible_module_vsphere_guest.py\", line 655, in deploy_template\n vmTemplate = vsphere_client.get_vm_by_name(template_src)\n File \"/usr/local/lib/python2.7/site-packages/pysphere/vi_server.py\", line 323, in get_vm_by_name\n FaultTypes.OBJECT_NOT_FOUND)\npysphere.resources.vi_exception.VIException: [Object Not Found]: Could not find a VM named 'templatename'\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}
This is the Ansible code:
---
- hosts: all
tasks:
- vsphere_guest:
validate_certs: no
guest: newbuildvm001
#state: powered_on
from_template: yes
template_src: templatename
vm_extra_config:
vcpu.hotadd: yes
mem.hotadd: yes
notes: This is a test VM
folder: Test
vm_disk:
disk1:
size_gb: 10
type: thin
datastore: test
folder: test-ansible
vm_nic:
nic1:
type: vmxnet3
network: teset
network_type: standard
vm_hardware:
memory_mb: 2048
num_cpus: 2
osid: centos64Guest
scsi: paravirtual
esxi:
datacenter: DC
I was expecting ansible to create a virtual machine based on the template called templatename.
Instead it seems to look for a virtual machine called templatename to clone?
vsphere_guest module clone existing VMs.
template_src is a name of VM (not template as you might expect) to clone from.
See proof in the module's code.

"Error reading package header" when using the Ansible yum install module

I have an ansible script that looks like this, and it was working properly yesterday -
- name: Dockerfile
hosts: localhost
connection: local
tasks:
- name: Install repositories packages
yum:
name: "{{ item }}"
state: present
with_items:
- https://centos7.iuscommunity.org/ius-release.rpm
- http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.10/CentOS/glusterfs-epel.repo
However this morning when I ran it, I got the following error -
failed: [localhost] (item=[u'https://centos7.iuscommunity.org/ius-release.rpm', u'http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.10/CentOS/glusterfs-epel.repo']) => {"failed": true, "invocation": {"module_name": "yum"}, "item": ["https://centos7.iuscommunity.org/ius-release.rpm", "http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.10/CentOS/glusterfs-epel.repo"], "module_stderr": "Traceback (most recent call last):\n File \"/tmp/ansible_mdVzzz/ansible_module_yum.py\", line 1064, in <module>\n main()\n File \"/tmp/ansible_mdVzzz/ansible_module_yum.py\", line 1053, in main\n disablerepo, disable_gpg_check, exclude, repoquery)\n File \"/tmp/ansible_mdVzzz/ansible_module_yum.py\", line 969, in ensure\n res = install(module, pkgs, repoq, yum_basecmd, conf_file, en_repos, dis_repos)\n File \"/tmp/ansible_mdVzzz/ansible_module_yum.py\", line 595, in install\n pkg_name = local_name(module, package)\n File \"/tmp/ansible_mdVzzz/ansible_module_yum.py\", line 492, in local_name\n header = ts.hdrFromFdno(fd)\n File \"/usr/lib64/python2.7/site-packages/rpm/transaction.py\", line 160, in hdrFromFdno\n raise rpm.error(\"error reading package header\")\n_rpm.error: error reading package header\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}
The actual error description is
raise rpm.error(\"error reading package header\")\n_rpm.error: error reading package header\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}
Did I break something? Or is this more of an issue with the gluster RPM?
Did you try this one:
- name: Install repositories packages
yum:
name: "{{ item }}"
state: present
with_items:
- https://centos7.iuscommunity.org/ius-release.rpm
- name: Install the gluster repo
get_url:
url: "http://download.gluster.org/pub/gluster/glusterfs/3.7/3.7.10/CentOS/glusterfs-epel.repo"
dest: "/etc/yum.repos.d/glusterfs-epel.repo"
mode: 0644

Error during Creation of VPC in AWS via Ansible

I am trying to create a VPC with the following code.
- name: VPC | Creating an AWS VPC inside mentioned Region
local_action:
module: ec2_vpc
region: "{{ vpc_region }}"
state: present
aws_access_key:
aws_secret_key:
cidr_block: "{{ vpc_cidr_block }}"
resource_tags: { "Name":"{{ vpc_name }}-vpc" }
subnets: "{{ vpc_subnets }}"
internet_gateway: yes
route_tables: "{{ public_subnet_rt }}"
register: vpc
passing the localhost as the host.
But I am facing the following error.
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/Users/Merv/.ansible/tmp/ansible-tmp-1462873251.31-168428606517499/ec2_vpc", line 2944, in <module>
main()
File "/Users/Merv/.ansible/tmp/ansible-tmp-1462873251.31-168428606517499/ec2_vpc", line 731, in main
(vpc_dict, new_vpc_id, subnets_changed, igw_id, changed) = create_vpc(module, vpc_conn)
File "/Users/Merv/.ansible/tmp/ansible-tmp-1462873251.31-168428606517499/ec2_vpc", line 339, in create_vpc
previous_vpc = find_vpc(module, vpc_conn, id, cidr_block)
File "/Users/Merv/.ansible/tmp/ansible-tmp-1462873251.31-168428606517499/ec2_vpc", line 199, in find_vpc
previous_vpcs = vpc_conn.get_all_vpcs(None, {'cidr': cidr, 'state': 'available'})
AttributeError: 'NoneType' object has no attribute 'get_all_vpcs'
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "invocation": {"module_name": "ec2_vpc"}, "module_stderr": "Traceback (most recent call last):\n File \"/Users/Merv/.ansible/tmp/ansible-tmp-1462873251.31-168428606517499/ec2_vpc\", line 2944, in <module>\n main()\n File \"/Users/Merv/.ansible/tmp/ansible-tmp-1462873251.31-168428606517499/ec2_vpc\", line 731, in main\n (vpc_dict, new_vpc_id, subnets_changed, igw_id, changed) = create_vpc(module, vpc_conn)\n File \"/Users/Merv/.ansible/tmp/ansible-tmp-1462873251.31-168428606517499/ec2_vpc\", line 339, in create_vpc\n previous_vpc = find_vpc(module, vpc_conn, id, cidr_block)\n File \"/Users/Merv/.ansible/tmp/ansible-tmp-1462873251.31-168428606517499/ec2_vpc\", line 199, in find_vpc\n previous_vpcs = vpc_conn.get_all_vpcs(None, {'cidr': cidr, 'state': 'available'})\nAttributeError: 'NoneType' object has no attribute 'get_all_vpcs'\n", "module_stdout": "", "msg": "MODULE FAILURE", "parsed": false}
I moved my boto version to 2.40.0 yet facing this issue.
yes It is a bug in the boto library. I installed the latest one. Also, this error persists if, the region name is wrong. So i changed my "{{ vpc_region }}" and this error went away.
Looks like, it a bug in boto library.
Found this: https://github.com/ansible/ansible-modules-core/issues/1772
For a temporary fix(as mentioned in the link):
To manually fix you can
add into each init.py
/usr/lib/python2.7/dist-packages/boto/ec2/init.py
your endpoints for example...
I added to the RegionData for this...
'eu-west-1a': 'ec2.eu-west-1.amazonaws.com',
'eu-west-1b': 'ec2.eu-west-1.amazonaws.com',
'eu-west-1c': 'ec2.eu-west-1.amazonaws.com',

Resources