cloud maps and overwrite providers: ValueError: need more than 1 value to unpack
Description of Issue/Question
I have two differents sites: siteA and siteB with the same templates. SiteA is my production site and siteB is the backup site both sites with VMware.
I am building machines both on the production site and on the backup site for this I generate a cloud file from a profile that I use as a template. In the profile is specified the provider that, by default, is siteA but when creating machines in siteB I overwrite this value to indicate that the virtual machine must be created in siteB, but salt returns the following error:
[ERROR ] Exception occurred in runner cloud.map_run: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/client/mixins.py", line 392, in _low
data['return'] = self.functions[fun](*args, **kwargs)
File "/usr/lib/python2.7/site-packages/salt/runners/cloud.py", line 126, in map_run
info = client.map_run(path, **_filter_kwargs(kwargs))
File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 360, in map_run
dmap = mapper.map_data()
File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 1988, in map_data
alias, driver = nodedata['provider'].split(':')
ValueError: need more than 1 value to unpack
According to the documentation (https://docs.saltstack.com/en/latest/topics/cloud/map.html) Any top level data element from your profile may be overridden in the map file.
Can I overwrite the provider section of a profile in the cloud map file through orchestrate state?
Setup
create_instance:
salt.runner:
- name: cloud.map_run
- kwarg:
# Lanzamos la creacion de las maquinas en paralelo
parallel: True
# Construimos el fichero mapa
map_data:
# Invocamos a la funcion que generara el fichero cloud mapa
redhat_7_x64_7-4_django:
# Definicion de la maquina a desplegar en ca90
prueba.srv.gva.es:
# Establecemos el proveedor donde crear la vm
provider: siteB
## Definicion de los dispositivos de la maquina virtual
devices:
network:
Network adapter 1:
name: 413_LAB_TEST
# Establecemos el tipo de vswitch
switch_type: standard
# Establecemos la configuracion ip
ip: 10.10.10.10
gateway: [10.10.10.1]
subnet_mask: 255.255.255.0
## Recursos de la maquina virtual
cluster: CL1_PLATA
datastore: dsv_pre_lin_02
extra_config:
guestinfo.hostname: prueba.localhost
# Profile: redhat_7_x64_7-4_django
# Perfil para la definicion de maquinas con el framework de aplicaciones
# python Django
redhat_7_x64_7-4_django:
## Parametros para desplegar una maquina virtual a partir de la
## plantilla
provider: siteA
clonefrom: redhat_7_x64_7-4_django
## Definicion de dispositivos: discos, tarjetas de red, etc.
## vCPUS & Memoria
num_cpus: 4
memory: 2GB
## Recursos de la maquina virtual
hardware_version: 10
extra_config:
mem.hotadd: 'yes'
cpu.hotadd: 'yes'
## Despliegue de agente salt-minion
deploy: True
Steps to Reproduce Issue
master:
----------
ID: create_instance
Function: salt.runner
Name: cloud.map_run
Result: False
Comment: Exception occurred in runner cloud.map_run: Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/client/mixins.py", line 392, in _low
data['return'] = self.functions[fun](*args, **kwargs)
File "/usr/lib/python2.7/site-packages/salt/runners/cloud.py", line 126, in map_run
info = client.map_run(path, **_filter_kwargs(kwargs))
File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 360, in map_run
dmap = mapper.map_data()
File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 1988, in map_data
alias, driver = nodedata['provider'].split(':')
ValueError: need more than 1 value to unpack
Started: 11:13:01.557621
Duration: 2775.481 ms
Changes:
Summary for master
------------
Succeeded: 0
Failed: 1
------------
Total states run: 1
Total run time: 2.775 s
Versions Report
master ~> sudo salt --versions-report
Salt Version:
Salt: 2017.7.1
Dependency Versions:
cffi: Not Installed
cherrypy: unknown
dateutil: Not Installed
docker-py: Not Installed
gitdb: Not Installed
gitpython: Not Installed
ioflo: Not Installed
Jinja2: 2.8.1
libgit2: Not Installed
libnacl: Not Installed
M2Crypto: Not Installed
Mako: Not Installed
msgpack-pure: Not Installed
msgpack-python: 0.4.6
mysql-python: Not Installed
pycparser: Not Installed
pycrypto: 2.6.1
pycryptodome: Not Installed
pygit2: Not Installed
Python: 2.7.13 (default, Jul 12 2017, 17:32:34)
python-gnupg: Not Installed
PyYAML: 3.11
PyZMQ: 14.5.0
RAET: Not Installed
smmap: Not Installed
timelib: Not Installed
Tornado: 4.2.1
ZMQ: 4.0.5
System Versions:
dist: centos 6.9 Santiago
locale: UTF-8
machine: x86_64
release: 2.6.32-642.15.1.el6.x86_64
system: Linux
version: Red Hat Enterprise Linux Server 6.9 Santiago
ping @saltstack/team-cloud anyone here know if this is suppose to be functional?
Let me provide a little more information. The cloud file map is generated through an orchestrate state that invokes the following macro:
{# Funcion macro que se encarga de construir el fichero cloud mapa a partir de un diccionario de maquinas
virtuales.
El formato del diccionario es:
list = {
'redhat_7_x64_7-4_django':{
'prueba.srv.gva.es':{'cesta': 12345667,
'entorno': 'pre',
'vlans': [413, 417, 471],
'cluster': 'CL1_PLATA',
'datastore': 'dsv_pre_lin_02',
'description': 'Pruebas salt cloud',
'roles': 'aplicaciones',
'grupo': ['14831ADMASA', 'ADMIN_SISCOM'],
'aplicacion':['tomcat'],
'provider': 'siteB'
}
}
}
donde:
redhat_7_x64_7-4_django: Plantilla con la que desplegar las vms
t1sageopython01.srv.gva.es: Maquina a desplegar con los datos requeridos
#}
{% macro deploy(list) %}
{#- Listamos las vms en la infraestructura para verificar si la maquina a desplegar
existe ya en la plataforma -#}
{%- set vmware = salt.saltutil.runner(name = 'cloud.query', arg=['list_nodes']) -%}
{# Recorremos el diccionario con las maquinas a desplegar para construir el fichero cloud map
Las maquinas estan agrupadas por plantillas #}
{% for template, vms in list.iteritems() %}
{# Recuperamos las maquinas asociadas a un profile template #}
{%- for hostname, settings in vms.iteritems() %}
{{ template }}:
{# Comprobamos si la vm esta ya creada en la infraestructura virtual #}
{% if settings['provider'] is defined %}
{% set provider = settings['provider'] %}
{% else %}
{% set provider = 'siteA' %}
{% endif %}
{%- if hostname not in vmware[provider]['vmware'] -%}
{# Creamos registro host en infoblox asociandolo a la vlan de servicio #}
{% set ip = salt.saltutil.runner(name = 'infoblox.create_host', kwarg={'hostname': hostname,
'vlan': settings['vlans'][0],
'cesta': settings['cesta']}
)['ipv4addrs'][0]['ipv4addr'] -%}
# Definicion de la maquina a desplegar en {{ settings['provider'] }}
{{ hostname }}:
# Establecemos el proveedor donde crear la vm
provider: {{ provider }}
# Especificamos las notas de la máquina
{# Obtenemos el Sistema Operativo de la plantilla que usaremos para desplegar la maquina
para referenciarlo en las notas #}
{%- if 'Linux' in vmware[settings['provider']]['vmware'][template]['image'] -%}
{% set machine = 'linux' %}
{% else %}
{% set machine = 'windows' %}
{%- endif -%}
annotations: "{{ settings['dominio']|upper }} - {{ machine|upper }} - {{ settings['entorno']|upper }}\n
Plantilla: {{ template }}\n
Cesta : {{ settings['cesta'] }}\n
Nombre : {{ hostname }}\n
IP : {{ ip }}\n
{% for vlan in settings['vlans'] -%}
VLAN : {{ vlan }}_{{ salt.saltutil.runner(name = 'infoblox.get_vlan', kwarg={'vlan_id': vlan})['extattrs']['VLAN Name'] }}\n
{% endfor -%}
Cluster : {{ settings['cluster'] }}\n
Servidor : {{ settings['description'] }}"
## Definicion de los dispositivos de la maquina virtual
devices:
network:
{%- for vlan in settings['vlans'] %}
{% set network = salt.saltutil.runner(name = 'infoblox.get_vlan', kwarg={'vlan_id': vlan} ) -%}
Network adapter {{ loop.index }}:
name: {{ vlan }}_{{ network['extattrs']['VLAN Name'] }}
# Establecemos el tipo de vswitch
{% if settings['vswitch'] is defined %}
switch_type: {{ settings['vswitch'] }}
{% else %}
switch_type: standard
{% endif %}
{# Establecemos el tipo de adaptador de red #}
{% if settings['adapter_type'] is defined %}
adapter_type: {{ settings['adapter_type'] }}
{% endif %}
# Establecemos la configuracion ip
{%- if vlan == settings['vlans'][0] %}
ip: {{ ip }}
gateway: [{{ network['gateway'] }}]
{%- else %}
ip: {{ salt.saltutil.runner(name = 'infoblox.add_ips', kwarg={'hostname': hostname,
'vlans': vlan}
)['ipv4addrs'][loop.index0]['ipv4addr'] }}
{%- endif %}
subnet_mask: {{ network['netmask'] }}
{% endfor %}
## Recursos de la maquina virtual
cluster: {{ settings['cluster'] }}
datastore: {{ settings['datastore'] }}
extra_config:
guestinfo.hostname: {{ hostname }}
## Parametros de despliegue del agente salt-minion
ssh_host: {{ ip }}
minion:
grains:
cesta: {{ settings['cesta'] }}
entorno: {{ settings['entorno'] }}
roles:
{{ settings['roles'] | yaml }}
grupo:
{{ settings['grupo'] | yaml }}
aplicacion:
{{ settings['aplicacion'] | yaml }}
{% if settings['dominio'] is defined %}
dominio: {{ settings['dominio'] }}
{% endif %}
{% else %}
# {{ hostname }} existe en: {{ provider }}
{% endif -%}
{%- endfor -%}
{% endfor -%}
{% endmacro %}
The objective is to invoke a state of orchestration by passing a dictionary with all the virtual machines with their characteristics including the provider (siteA or siteB). The state works correctly as long as the dictionary does not contain the provider.
Thanks a lot
Yeah, i think you will need to provide the full provider which is a combination of the alias and the driver.
provider: "siteB:<driver>"
If siteB uses the openstack driver, you would set it to "siteB:openstack", or "siteB:ec2" for the ec2 driver.
This should work, by the time it gets to the point where the map is overwriting profile information, we have already joined the provider "name" and the driver to be the provider object inside the profiles as they are rendered for salt to use. This is a slightly different data structure than what is in the cloud configuration files.
Daniel
Thanks @gtmanfred, I'll try it tomorrow and I'll confirm it.
The modified code would look like:
{% if settings['provider'] is defined %}
{% set provider = settings['provider'] + ":vmware"%}
{% else %}
{% set provider = 'siteA:vmware' %}
{% endif %}
{%- if hostname not in vmware[provider]['vmware'] -%}
{# Creamos registro host en infoblox asociandolo a la vlan de servicio #}
{% set ip = salt.saltutil.runner(name = 'infoblox.create_host', kwarg={'hostname': hostname,
'vlan': settings['vlans'][0],
'cesta': settings['cesta']}
)['ipv4addrs'][0]['ipv4addr'] -%}
# Definicion de la maquina a desplegar en {{ settings['provider'] }}
{{ hostname }}:
# Establecemos el proveedor donde crear la vm
provider: "{{ provider }}"
@gtmanfred, I've tried the settings you indicated. The orchestration state is correctly generated and we start to generate the minion key but when it is going to launch the cloning of the vm it does not find the provider's information:
[DEBUG ] Generating minion keys for 'prueba.local'
[ERROR ] Failed to create VM prueba.local. Configuration value 'w2012_r2_std_edt' needs to be set
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/salt/cloud/__init__.py", line 1287, in create
output = self.clouds[func](vm_)
File "/usr/lib/python2.7/site-packages/salt/cloud/clouds/vmware.py", line 2309, in create
vm_=vm_) is False:
File "/usr/lib/python2.7/site-packages/salt/config/__init__.py", line 3184, in is_profile_configured
profile_key = opts['providers'][alias][driver]['profiles'][profile_name]
KeyError: 'w2012_r2_std_edt'
[DEBUG ] Sending event: tag = salt/run/20171129085016882489/ret; data = {'fun_args': [{'map_data': OrderedDict([('w2012_r2_std_edt', {'prueba.local': OrderedDict([('provider', 'siteB:vmware'), ('annotations', 'SITEB - WINDOWS - PRE\n Plantilla: w2012_r2_std_edt\n Cesta : 12345667\n Nombre : prueba.local\n'), ('devices', OrderedDict([('network', OrderedDict([('Network adapter 1', OrderedDict([('name', '413'), ('switch_type', 'standard'), ('ip', '10.10.10.2'), ('gateway', ['10.10.10.1']), ('subnet_mask', '255.255.254.0')])])), ('cluster', 'CL1_PLATA'), ('datastore', 'dsv_pre_lin_02'), ('extra_config', OrderedDict([('guestinfo.hostname', 'prueba.local')])), ('ssh_host', '10.10.10.1'), ('name', 'prueba.local')])})]), 'parallel': True}], 'jid': '20171129085016882489', 'return': {'prueba.local': {}}, 'success': True, '_stamp': '2017-11-29T07:50:42.937449', 'user': 'UNKNOWN', 'fun': 'runner.cloud.map_run'}
[DEBUG ] LazyLoaded local_cache.prep_jid
[INFO ] Runner completed: 20171129085016882489
[INFO ] {'prueba.local': {}}
[INFO ] Completed state [cloud.map_run] at time 08:50:42.942934 duration_in_ms=26705.496
[DEBUG ] File /var/cache/salt/master/accumulator/140700000935696 does not exist, no need to cleanup.
[DEBUG ] LazyLoaded config.option
[DEBUG ] Sending event: tag = salt/run/20171129084952670881/ret; data = {'fun_args': ['orchestrate.prueba', {'orchestration_jid': '20171129084952670881'}], 'jid': '20171129084952670881', 'return': {'outputter': 'highstate', 'data': {'master': {'salt_|-create_instance_|-cloud.map_run_|-runner': {'comment': "Runner function 'cloud.map_run' executed.", 'name': 'cloud.map_run', '__orchestration__': True, 'start_time': '08:50:16.237438', 'result': True, 'duration': 26705.496, '__run_num__': 0, '__jid__': '20171129085016882489', '__sls__': u'orchestrate.prueba', 'changes': {'prueba.local': {}}, '__id__': 'create_instance'}}}, 'retcode': 0}, 'success': True, '_stamp': '2017-11-29T07:50:42.948337', 'user': 'sudo_user, 'fun': 'runner.state.orchestrate'}
[DEBUG ] LazyLoaded highstate.output
[DEBUG ] LazyLoaded nested.output
master:
----------
ID: create_instance
Function: salt.runner
Name: cloud.map_run
Result: True
Comment: Runner function 'cloud.map_run' executed.
Started: 08:50:16.237438
Duration: 26705.496 ms
Changes:
----------
prueba.local:
----------
Summary for master
------------
Succeeded: 1 (changed=1)
Failed: 0
------------
Total states run: 1
Total run time: 26.705 s
the cloud map file generated is:
create_instance:
salt.runner:
- name: cloud.map_run
- kwarg:
# Lanzamos la creacion de las maquinas en paralelo
parallel: True
# Construimos el fichero mapa
map_data:
# Invocamos a la funcion que generara el fichero cloud mapa
w2012_r2_std_edt:
# Definicion de la maquina a desplegar en ca90
prueba.local:
# Establecemos el proveedor donde crear la vm
provider: "siteB:vmware"
# Especificamos las notas de la máquina
annotations: "SITEB - Linux - PRE\n
Plantilla: w2012_r2_std_edt\n
Cesta : 12345667\n
Nombre : prueba.srv.gva.es\n
IP : 172.27.150.77\n"
## Definicion de los dispositivos de la maquina virtual
devices:
network:
Network adapter 1:
name: 413
# Establecemos el tipo de vswitch
switch_type: standard
# Establecemos la configuracion ip
ip: 10.10.10.2
gateway: [10.10.10.1]
subnet_mask: 255.255.254.0
## Recursos de la maquina virtual
cluster: CL1_PLATA
datastore: dsv_pre_lin_02
extra_config:
guestinfo.hostname: prueba.local
## Parametros de despliegue del agente salt-minion
ssh_host: 10.10.10.2
Thanks a lot
Ok, then if that doesn't work, it wont be possible with the current release.
We will need to mark this as a feature request, to allow changing the provider from a map file.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.
I believe this was added in 2019.2.0