ansible / molecule

Molecule aids in the development and testing of Ansible content: collections, playbooks and roles
https://ansible.readthedocs.io/projects/molecule/
MIT License
3.89k stars 664 forks source link

molecule create task seems to have an issue on IdentityFile dict #1161

Closed Raffaello closed 6 years ago

Raffaello commented 6 years ago

Issue Type

Molecule and Ansible details

ansible 2.3.4
molecule 2.9.0

Actual Behaviour (Bug report only)

--> Action: 'create'

    PLAY [Create] ******************************************************************

    TASK [Create molecule instance(s)] *********************************************
    changed: [localhost] => (item=None)

    TASK [Populate instance config dict] *******************************************
    fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'IdentityFile'\n\nThe error appears to have been in '/**/molecule/default/create.yml': line 36, column 7, but maybe elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

   - name: Populate instance config dict
      ^ here\n\nexception type: <class 'ansible.errors.AnsibleUndefinedVariable'>\nexception: 'dict object' has no attribute 'IdentityFile'"}
Raffaello commented 6 years ago

it seems related to not finding the ssh key anymore... the output of vagrant ssh-config:

Host xenial64
  HostName 127.0.0.1
  User ubuntu
  Port 2203
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentitiesOnly yes
  LogLevel FATAL

and it is missing IdentityFile. Any reason why it is happening?

retr0h commented 6 years ago

Do you have something in ~/.vagrant.d/Vagrantfile?

Raffaello commented 6 years ago

Nope. I do not have neither that file.

retr0h commented 6 years ago

Does the problem go away if you try a different version of Molecule? Could you try pip install molecule==2.8.2. I'm wondering if #1147, somehow causes this issue.

Raffaello commented 6 years ago

with version 2.8.2 is working properly.

and with 2.9.0 is getting me the error.

retr0h commented 6 years ago

@Raffaello can you add the following provider_options to your Molecule 2.9.0 create.yml.

molecule_vagrant:
  provider_options:
    ssh_insert_key: true
Raffaello commented 6 years ago

i have this error

    failed: [localhost] (item={'box': u'ubuntu/xenial64', 'name': u'xenial64'}) => {                     
        "changed": false, 
        "item": {         
            "box": "ubuntu/xenial64",               
            "name": "xenial64"                      
        },                
        "module_stderr": "There are errors in the configuration of this machine. Please fix\nthe following errors and try again:\n\nVirtualBox Provider:\n* The following settings shouldn't exist: ssh_insert_key\n\nTraceback (most recent call last):\n  File \"/tmp/ansible_Y1PPqN/ansible_module_molecule_vagrant.py\", line 463, in <module>\n    main()\n  File \"/tmp/ansible_Y1PPqN/ansible_module_molecule_vagrant.py\", line 456, in main\n    v.up()\n  File \"/tmp/ansible_Y1PPqN/ansible_module_molecule_vagrant.py\", line 342, in up\n    for line in self._vagrant.up(provision=provision, stream_output=True):\n  File \"venv_molecule/lib/python2.7/site-packages/vagrant/__init__.py\", line 1005, in _stream_vagrant_command\n    raise subprocess.CalledProcessError(p.returncode, command) subprocess.CalledProcessError: Command '['/usr/bin/vagrant', 'up', '--no-provision']' returned non-zero exit status 1\n", 
        "module_stdout": "<vagrant_output> Bringing machine 'xenial64' up with 'virtualbox' provider...\n\n", 
        "msg": "MODULE FAILURE",                    

the generated vagrant.yml file seems correct to me:

provider:
  name: virtualbox
  options:
    cpus: 2
    memory: 512
    ssh_insert_key: true

basically, seems the error on vagrant itself:

Bringing machine 'xenial64' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:

VirtualBox Provider:
* The following settings shouldn't exist: ssh_insert_key

vagrant version: 2.0.2

and it is strictly related to the line in the vagarnt.yml file. if i comment it out. vagrant up is not complaining anymore

Raffaello commented 6 years ago

it fails for this point in the Vagrant file template: https://github.com/metacloud/molecule/blob/master/molecule/provisioner/ansible/plugins/libraries/molecule_vagrant.py#L192-L199

excluding also ssh_insert_key and run vagrant validate doesn't reproduce anymore the error output.

if key != 'memory' and key != 'cpus' and key != 'linked_clone' and key != 'ssh_insert_key'

i created a PR

https://github.com/metacloud/molecule/pull/1168

retr0h commented 6 years ago

@Raffaello does your fix in #1168 fix the reported issue?

retr0h commented 6 years ago

v2.10 was cut to fix this issue.

Raffaello commented 6 years ago

yes. I tested only with virtualbox, i saw in the template there are other providers (eg: vmware), but i am not able to test them.