snowdrop / k8s-infra

Information to bootstrap vms using dedicated server, local machine and setup using Ansible Playbooks
Apache License 2.0
29 stars 14 forks source link

Creation of an new VM on Openstack fails using ansible playbook #293

Closed cmoulliard closed 1 year ago

cmoulliard commented 1 year ago

Issue

TASK [openstack/vm : Create VM instance] *******************************************************************************************************************************************************************************
Friday 14 April 2023  11:10:56 +0200 (0:00:00.033)       0:00:35.642 **********
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable.
The error was: list object has no element 0
The error appears to be in '/Users/cmoullia/code/snowdrop/k8s-infra/ansible/roles/openstack/vm/tasks/vm_create.yml': line 112, column 5, but may be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
  - name: \"Create VM instance\"
  -     ^ here
  - "}

Command executed:

VM_NAME=tap-1.5
ansible-playbook ansible/playbook/openstack/openstack_vm_create_paswordstore.yml 
-e k8s_type=masters 
-e k8s_version=124 
-e '{"openstack": {"vm": {
"network": "provider_net_shared","image": 
"RHEL-8.7.0-x86_64-ga-latest", 
"flavor": "g.standard.xxl"}}}' 
-e key_name=tap-1.5-key 
-e vm_name=${VM_NAME}

Parameters are well declared:

TASK [openstack/vm : Print parameters defined to create the VM on Openstack] ********************************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        "auth",
        "  project_name: \"spring-boot-jenkins\"",
        "  username: \"psi-spring-boot-jenkins\"",
        "  password: \"xxxxxxxxxxx\"",
        "  user_domain_name: \"redhat.com\"",
        "  project_domain_name: \"redhat.com\"",
        "  auth_url: \"https://rhos-d.infra.prod.upshift.rdu2.redhat.com:13000/v3/\"",
        "name: \"tap-15\"",
        "image: \"RHEL-8.7.0-x86_64-ga-latest\"",
        "key_name: \"tap-1.5-key\"",
        "state: \"present\"",
        "timeout: \"60000\"",
        "flavor: \"g.standard.xxl\"",
        "auto_floating_ip: yes",
        "network: \"provider_net_shared\"",
        "security_groups: \"spring-boot\"",
        "volumes: \"tap-15-volume\"",
        "boot_from_volume: \"False\"",
        ""
    ]
}
cmoulliard commented 1 year ago

I think that the issue is coming from this key/value key_name=tap-1.5-key as I can create a vm using key_name=test-adm-key. Why ? I dont know

cmoulliard commented 1 year ago

By the way, I'm getting this new error now

TASK [openstack/vm : Print parameters defined to create the VM on Openstack] *******************************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        "auth",
        "  project_name: \"spring-boot-jenkins\"",
        "  username: \"psi-spring-boot-jenkins\"",
        "  password: \"xxxxxxxx\"",
        "  user_domain_name: \"redhat.com\"",
        "  project_domain_name: \"redhat.com\"",
        "  auth_url: \"https://rhos-d.infra.prod.upshift.rdu2.redhat.com:13000/v3/\"",
        "name: \"tap15\"",
        "image: \"RHEL-8.7.0-x86_64-ga-latest\"",
        "key_name: \"test-adm-key\"",
        "state: \"present\"",
        "timeout: \"60000\"",
        "flavor: \"g.standard.xxl\"",
        "auto_floating_ip: yes",
        "network: \"provider_net_shared\"",
        "security_groups: \"spring-boot\"",
        "volumes: \"tap15-volume\"",
        "boot_from_volume: \"False\"",
        "Key: \"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0J5f7peUf+ahTGq7i7jm6Qsa7p67YHTJr1omIe+fWKcxiFXWsw6Ohp1L4HanwvCRVdmrKQTi8tqHc+YhhPRNMJ8zdMxKUpXSAm/WQq6xFKIMq1dkoC9ZNfnhakXYI1hPLMvno1P22uuLVOkguVQ0rUDsIlf5Uar+RVTEbd3FA7olvk0wBKz8LqnPDJzREI/eDcHv4RAKyXypNdlCC0Py4/hg68FdB/7O7R7j7fNMeXFIbWlo+OPfSOvDn5u79jkNGrT7V+dFiPW5E9CHdJuy2bdOKhd5TRvOo52hkaVpyX/1Xb8ZCSgMe0ggSbbaJhr/LOI6qRs1FU5BbXgo5ShzJ ajc102@localhost.localdomain\"",
        ""
    ]
}

TASK [openstack/vm : Create VM instance] *******************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'volumes is not found. 
openstack.compute.v2.server.Server objects do not support setting arbitrary keys through the dict interface.'

fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/Users/cmoullia/.ansible/tmp/ansible-tmp-1681467667.2980611-23053-165144121084652/AnsiballZ_server.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/Users/cmoullia/.ansible/tmp/ansible-tmp-1681467667.2980611-23053-165144121084652/AnsiballZ_server.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/cmoullia/.ansible/tmp/ansible-tmp-1681467667.2980611-23053-165144121084652/AnsiballZ_server.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.openstack.cloud.plugins.modules.server', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/local/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 225, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/local/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/local/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/modules/server.py\", line 805, in <module>\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/modules/server.py\", line 801, in main\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/module_utils/openstack.py\", line 407, in __call__\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/modules/server.py\", line 551, in run\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/modules/server.py\", line 633, in _create_server\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/modules/server.py\", line 558, in _exit_hostvars\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible/module_utils/basic.py\", line 2176, in exit_json\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible/module_utils/basic.py\", line 2169, in _return_formatted\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible/module_utils/basic.py\", line 436, in remove_values\n  File \"/usr/local/Cellar/ansible@2.9/2.9.27_4/libexec/lib/python3.9/site-packages/openstack/resource.py\", line 711, in __setitem__\
raise KeyError(KeyError: 
'volumes is not found. openstack.compute.v2.server.Server objects do not support setting arbitrary keys through the dict interface.'
", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

WARNING: Even if we got the error, the Openstack VM has been well created.

NOTE: It has been needed that I add manually the ansible_ssh_host key to openstack/tap15 and that I create under my host machine the file $HOME/.ssh/id_rsa_snowdrop_openstack_tap15 with the test-adm private key to been able to ssh

jacobdotcosta commented 1 year ago

The task includes an option with an undefined variable

Probably because of the dot (.) on the VM name, I have to test it.

jacobdotcosta commented 1 year ago

By the way, I'm getting this new error now

TASK [openstack/vm : Print parameters defined to create the VM on Openstack] *******************************************************************************************************************************************
ok: [localhost] => {
    "msg": [
        "auth",
        "  project_name: \"spring-boot-jenkins\"",
        "  username: \"psi-spring-boot-jenkins\"",
        "  password: \"xxxxxxxx\"",
        "  user_domain_name: \"redhat.com\"",
        "  project_domain_name: \"redhat.com\"",
        "  auth_url: \"https://rhos-d.infra.prod.upshift.rdu2.redhat.com:13000/v3/\"",
        "name: \"tap15\"",
        "image: \"RHEL-8.7.0-x86_64-ga-latest\"",
        "key_name: \"test-adm-key\"",
        "state: \"present\"",
        "timeout: \"60000\"",
        "flavor: \"g.standard.xxl\"",
        "auto_floating_ip: yes",
        "network: \"provider_net_shared\"",
        "security_groups: \"spring-boot\"",
        "volumes: \"tap15-volume\"",
        "boot_from_volume: \"False\"",
        "Key: \"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC0J5f7peUf+ahTGq7i7jm6Qsa7p67YHTJr1omIe+fWKcxiFXWsw6Ohp1L4HanwvCRVdmrKQTi8tqHc+YhhPRNMJ8zdMxKUpXSAm/WQq6xFKIMq1dkoC9ZNfnhakXYI1hPLMvno1P22uuLVOkguVQ0rUDsIlf5Uar+RVTEbd3FA7olvk0wBKz8LqnPDJzREI/eDcHv4RAKyXypNdlCC0Py4/hg68FdB/7O7R7j7fNMeXFIbWlo+OPfSOvDn5u79jkNGrT7V+dFiPW5E9CHdJuy2bdOKhd5TRvOo52hkaVpyX/1Xb8ZCSgMe0ggSbbaJhr/LOI6qRs1FU5BbXgo5ShzJ ajc102@localhost.localdomain\"",
        ""
    ]
}

TASK [openstack/vm : Create VM instance] *******************************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: KeyError: 'volumes is not found. 
openstack.compute.v2.server.Server objects do not support setting arbitrary keys through the dict interface.'

fatal: [localhost]: FAILED! => {"changed": false, "module_stderr": "Traceback (most recent call last):\n  File \"/Users/cmoullia/.ansible/tmp/ansible-tmp-1681467667.2980611-23053-165144121084652/AnsiballZ_server.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/Users/cmoullia/.ansible/tmp/ansible-tmp-1681467667.2980611-23053-165144121084652/AnsiballZ_server.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/cmoullia/.ansible/tmp/ansible-tmp-1681467667.2980611-23053-165144121084652/AnsiballZ_server.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.openstack.cloud.plugins.modules.server', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/local/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 225, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/local/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/local/Cellar/python@3.9/3.9.16/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/modules/server.py\", line 805, in <module>\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/modules/server.py\", line 801, in main\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/module_utils/openstack.py\", line 407, in __call__\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/modules/server.py\", line 551, in run\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/modules/server.py\", line 633, in _create_server\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible_collections/openstack/cloud/plugins/modules/server.py\", line 558, in _exit_hostvars\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible/module_utils/basic.py\", line 2176, in exit_json\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible/module_utils/basic.py\", line 2169, in _return_formatted\n  File \"/var/folders/t2/jwchtqkn5y76hrfrws7dqtqm0000gn/T/ansible_openstack.cloud.server_payload_4tqff_f8/ansible_openstack.cloud.server_payload.zip/ansible/module_utils/basic.py\", line 436, in remove_values\n  File \"/usr/local/Cellar/ansible@2.9/2.9.27_4/libexec/lib/python3.9/site-packages/openstack/resource.py\", line 711, in __setitem__\
raise KeyError(KeyError: 
'volumes is not found. openstack.compute.v2.server.Server objects do not support setting arbitrary keys through the dict interface.'
", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

WARNING: Even if we got the error, the Openstack VM has been well created.

NOTE: It has been needed that I add manually the ansible_ssh_host key to openstack/tap15 and that I create under my host machine the file $HOME/.ssh/id_rsa_snowdrop_openstack_tap15 with the test-adm private key to been able to ssh

Those elements had to be created manually because it seems that the playbook didn't finish due to the error in the VM creation task. Had the playbook finish successfully, those elements should have been added to the passwordstore.