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.88k stars 662 forks source link

Molecule checks playbook syntax too early (before requirement.yml is resolved) #332

Closed tknerr closed 8 years ago

tknerr commented 8 years ago

Using a requirements.yml like that:


---
- name: timezone
  src: yatesr.timezone

With this molecule.yml:


---
#
# see here for the possible configuration options:
# https://molecule.readthedocs.io/en/master/usage.html#configuration
#

# configure serverspec and testinfra directories
molecule:
  serverspec_dir: disabled
  testinfra_dir: spec

# force the ssh connection
testinfra:
  connection: ssh
  hosts: helloworld
  ssh-config: .vagrant/ssh-config
  spec: yes

# ansible specific configuration, disabling SSH connection sharing
ansible:
  playbook: site.yml
  verbose: vvvv
  requirements_file: requirements.yml
  raw_ssh_args:
    - -o UserKnownHostsFile=/dev/null
    - -o IdentitiesOnly=yes
    - -o ControlMaster=no

# vagrant and instances configuration
vagrant:
  raw_config_args:
    - "ssh.insert_key = false"
  platforms:
    - name: ubuntu1604
      box: bento/ubuntu-16.04
  providers:
    - name: virtualbox
      type: virtualbox
      options:
        name: '"molecule-helloworld"'
        memory: 512
        cpus: 2
  instances:
    - name: helloworld
      options:
        append_platform_to_hostname: no

When I run molecule test, it fails because it can not find the "timezone" dependency role:

Y:\repo\devops\devops-acceptance-tests\vagrant-ansible>molecule test
--> Destroying instances ...
--> Checking playbooks syntax ...
Using .molecule/ansible.cfg as config file
ERROR! the role 'timezone' was not found in /cygdrive/y/repo/devops/devops-acceptance-tests/vagrant-ansible/roles:/cygdrive/y/repo/devops/devops-acceptance-tests/vagrant-ansible:./roles

The error appears to have been in '/cygdrive/y/repo/devops/devops-acceptance-tests/vagrant-ansible/site.yml': line 4, column 7, but may
be elsewhere in the file depending on the exact syntax problem.

The offending line appears to be:

  roles:
    - timezone
      ^ here

None

Imho it should first resolve the dependecies via ansible-galaxy, then check the playbook syntax.

retr0h commented 8 years ago

Duplicate of #288.

tknerr commented 8 years ago

Workaround is to manually put the syntax check after the converge step:

molecule:
  test:
    sequence: [ destroy, create, converge, syntax, idempotence, verify ]

Maybe you can even add this to ~/.config/molecule/config.yml globally in the meantime (thanks @kireledan)

tknerr commented 8 years ago

quick confirmation that putting it into ~/.config/molecule/config.yml works as expected, ie. you don't have to repeat it in every project's molecule.yml

tknerr commented 8 years ago

maybe a separate command / step for dependencies vs converge would be the proper solution though, e.g. sequence: [ destroy, dependencies, syntax, create, converge, idempotence, verify ] as the default

retr0h commented 8 years ago

molecule: test: sequence: [ destroy, create, converge, syntax, idempotence, verify ]

The only problem with modifying the sequence, we end up converging before we run the syntax check. That makes the syntax check moot.

tknerr commented 8 years ago

Oh right, it's only syntax. Thought of it more like linting, which would be late, but still useful... So makes no sense to do it after converge, so I will just skip it completely in my workaround

retr0h commented 8 years ago

Resolved with #340.