Giter VIP home page Giter VIP logo

ansible / molecule Goto Github PK

View Code? Open in Web Editor NEW
3.8K 112.0 648.0 13.75 MB

Molecule aids in the development and testing of Ansible content: collections, playbooks and roles

Home Page: https://ansible.readthedocs.io/projects/molecule/

License: MIT License

Python 99.22% Shell 0.28% Jinja 0.50%
python ansible testing testing-framework testinfra molecule-driver podman cookiecutter-ansible hacktoberfest supports-dot-config

molecule's Introduction

About Ansible Molecule

PyPI Package Documentation Status image Python Black Code Style Ansible Code of Conduct Discussions Repository License

Molecule project is designed to aid in the development and testing of Ansible roles.

Molecule provides support for testing with multiple instances, operating systems and distributions, virtualization providers, test frameworks and testing scenarios.

Molecule encourages an approach that results in consistently developed roles that are well-written, easily understood and maintained.

Molecule supports only the latest two major versions of Ansible (N/N-1), meaning that if the latest version is 2.9.x, we will also test our code with 2.8.x.

Once installed, the command line can be called using any of the methods below:

molecule ...
python3 -m molecule ...  # python module calling method

Documentation

Read the documentation and more at https://molecule.readthedocs.io/.

Get Involved

If you want to get moving fast and make a quick patch:

$ git clone https://github.com/ansible-community/molecule && cd molecule
$ python3 -m venv .venv && source .venv/bin/activate
$ python3 -m pip install -U setuptools pip tox

And you're ready to make your changes!

Authors

Molecule project was created by Retr0h and it is now community-maintained as part of the Ansible by Red Hat project.

License

The MIT License.

The logo is licensed under the Creative Commons NoDerivatives 4.0 License.

If you have some other use in mind, contact us.

molecule's People

Contributors

abtreece avatar alop avatar alvaroaleman avatar ansible-zuul[bot] avatar apatard avatar audgirka avatar bborysenko avatar brianhelba avatar decentral1se avatar dependabot[bot] avatar dhutty avatar greg-hellings avatar gundalow avatar kireledan avatar lwm avatar markusteufelberger avatar pre-commit-ci[bot] avatar pyup-bot avatar retr0h avatar rgreinho avatar robertdebock avatar seandst avatar signed8bit avatar ssbarnea avatar sshnaidm avatar tadeboro avatar themr0c avatar webknjaz avatar wilmardo avatar zhan9san avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

molecule's Issues

Can't run serverspec tests

Using the default config from the docs, the tests in spec/*_spec.rb aren't run:

$ molecule init foo
Successfully initialized new role in ./foo/
$ cd foo
$ molecule test
Bringing machine 'foo-01' up with 'virtualbox' provider...
==> foo-01: Cloning VM...
==> foo-01: Matching MAC address for NAT networking...
==> foo-01: Setting the name of the VM: foo_foo-01_1455095810804_66684
==> foo-01: Clearing any previously set forwarded ports...
==> foo-01: Fixed port collision for 22 => 2222. Now on port 2208.
==> foo-01: Clearing any previously set network interfaces...
==> foo-01: Preparing network interfaces based on configuration...
    foo-01: Adapter 1: nat
    foo-01: Adapter 2: hostonly
==> foo-01: Forwarding ports...
    foo-01: 22 (guest) => 2208 (host) (adapter 1)
==> foo-01: Running 'pre-boot' VM customizations...
==> foo-01: Booting VM...
==> foo-01: Waiting for machine to boot. This may take a few minutes...
    foo-01: SSH address: 127.0.0.1:2208
    foo-01: SSH username: vagrant
    foo-01: SSH auth method: private key
==> foo-01: Machine booted and ready!
==> foo-01: Checking for guest additions in VM...
==> foo-01: Setting hostname...
==> foo-01: Configuring and enabling network interfaces...
==> foo-01: Mounting shared folders...
    foo-01: /vagrant => /tmp/foo
==> foo-01: Machine not provisioned because `--no-provision` is specified.

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [foo-01]

PLAY RECAP *********************************************************************
foo-01                     : ok=1    changed=0    unreachable=0    failed=0   

Idempotence test in progress (can take a few minutes)...
Idempotence test passed.
Trailing whitespace found in ./meta/main.yml on lines: 3, 5, 9, 18, 28, 140
$ molecule verify
Trailing whitespace found in ./meta/main.yml on lines: 3, 5, 9, 18, 28, 140
$ vim ./meta/main.yml
$ molecule verify
============================= test session starts ==============================
platform linux2 -- Python 2.7.9, pytest-2.8.7, py-1.4.31, pluggy-0.3.1
rootdir: /tmp/foo, inifile: 
plugins: testinfra-1.0.1
collected 0 items 

========================= no tests ran in 0.00 seconds =========================
ERROR: 

  RAN: '/home/conor/.local/bin/testinfra --connection=ansible --sudo --ansible-inventory=.molecule/ansible_inventory'

  STDOUT:


  STDERR:

$ find spec/
spec/
spec/groups
spec/hosts
spec/default_spec.rb
spec/spec_helper.rb

Not sure what's prohibiting the spec/default_spec.rb from being found, especially because testinfra tries to run. Let me know if I can provide more info.

Question: running commands on multiple instances

Hi!

When I'm developing Ansible roles I usually target multiple operating systems or multiple versions of a single operating system.

Let's say I have molecule.yml which has the following vagrant section:

vagrant:
  raw_config_args:
    - "ssh.insert_key = false"

  platforms:
    - name: centos7
      box: centos/7
    - name: fedora23
      box: fedora/23-cloud-base
      # Install Python 2 and dependencies
      # NOTE: This is a work-around to make Ansible work with the Fedora 23's
      # official Vagrant box which doesn't include Python 2
      triggers:
        - trigger: after
          action: up
          cmd: run_remote 'dnf install -y python2 python2-dnf libselinux-python'

  providers:
    - name: virtualbox
      type: virtualbox

  instances:
    - name: test
      ansible_groups:
        - molecule
      interfaces:
        - network_name: private_network
          type: dhcp
          auto_config: true

How can I work with multiple supported platforms (namely, centos7 and fedora23)?

  • Do I define multiple instances, one for each supported platform? How can I specify which platform an instance uses in instance's definition in molecule.yml?
  • Can I specify a parameter to molecule commands that will tell Molecule to iterate through all supported platforms? Is it possible to specify a setting to pass this parameter to molecule commands by default?

Trailing whitespace in molecule.yml after molecule init

molecule.yml is the default one created with molecule init

(molecule)user $  molecule verify
Trailing whitespace found in ./molecule.yml on lines: 100

At # box_version:

  # molecule's --platform option will look for these names
  platforms:
    - name: trusty64
      box: trusty64
      box_url: https://vagrantcloud.com/ubuntu/boxes/trusty64/versions/14.04/providers/virtualbox.box
      # Optional item, box_version - support for vagrant versioning
      # box_version: 

The vagrant not support static ip assignment

Although currently the network type could be set as static, but there's no ip parameter could be set, it end with below error.

(venv)[email protected]_server$ molecule converge  --platform=rhel-7
Bringing machine 'pxe-server-01-rhel-7' up with 'virtualbox' provider...
Bringing machine 'pxe-client-01-rhel-7' up with 'virtualbox' provider...
There are errors in the configuration of this machine. Please fix
the following errors and try again:
vm:
* An IP is required for a private network.

In molecule.yml

    - name: pxe-server-01
      ansible_groups:
        - aio
        - pxe_server
      interfaces:
        - network_name: private_network
          type: static
          ip: 192.168.11.3
          auto_config: true

Feature idea: Add a new molecule command to perform check (dry run)

Supporting --check mode for Ansible roles isn't trivial; you have to make sure any tasks that register variables are read-only and marked with always_run: true. Personally I'm a big fan of leveraging check mode, but I think the difficulty of testing it makes many folks writing Ansible roles leave it by the wayside. Molecule can help with that.

As low-hanging fruit during edits for #110, adding an additional (optional) stage for the test functionality would be great:

  test:
    # sequence of commands to run when performing `molecule test`
    sequence:
      - destroy
      - syntax-check
      - create
      - converge
      - idempotence
      - check
      - verify
      - destroy

Comments welcome.

Increase visibility of ssh

In the interests of troubleshooting obscure ssh config problems, it would helpful if we could allow serverspec to show complete output from the ssh connection, as if it were made with -vvv.

Testinfra integration

Hi, I'm the author of testinfra and I'm pretty happy to see you integrate it in molecule.

Recently I added ansible helpers into testinfra:

Using ansible backend will allow you to use your existing ansible configuration (inventory, host, user, password, sudo, ssh-key etc) instead of define a testinfra_hosts in you test file and make a call to vagrant ssh-config (which is pretty long). Also this make the Ansible module available in your testinfra tests.

Jinja2 runtime error for followlinks argument of FileSystemLoader

Attempting to run molecule on a system with Jinja2 already installed yields the following error:

$ molecule -v
1.4.1
$ molecule create
Traceback (most recent call last):
  File "/usr/local/bin/molecule", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/site-packages/molecule/cli.py", line 66, in main
    CLI().main()
  File "/usr/local/lib/python2.7/site-packages/molecule/cli.py", line 62, in main
    sys.exit(c.execute()[0])
  File "/usr/local/lib/python2.7/site-packages/molecule/commands.py", line 116, in execute
    self.molecule._create_templates()
  File "/usr/local/lib/python2.7/site-packages/molecule/core.py", line 188, in _create_templates
    kwargs=kwargs)
  File "/usr/local/lib/python2.7/site-packages/molecule/utilities.py", line 95, in write_template
    loader = ChoiceLoader([FileSystemLoader(path, followlinks=True), PackageLoader(_module, _dir)])
TypeError: __init__() got an unexpected keyword argument 'followlinks'

Looking at the Jinja2 CHANGELOG, the followlinks keyword was added in version 2.8. Perhaps the Jinja2 dependency for Molecule need to be >=2.8?

Instance raw_config_arg merging is broken

Given this:

  instances:
    - name: instance-01
      raw_config_args:
        - "vm.network 'forwarded_port', guest: 8111, host: 8080"
        - "vm.network 'forwarded_port', guest: 8112, host: 8081"

Debug shows raw_config_args is converted to this:

    raw_config_args:
    - 'vm.network ''forwarded_port'', guest: 8112, host: 8080'

Because of how the two lines are mixed, this potentially looks like a bug with our dict merging.

Molecule login is broken in 1.5.0

The docker changes provided by @kireledan look like they broke molecule login when using vagrant.

$ molecule login
Traceback (most recent call last):
  File "/Users/regreinh/projects/ansible-engineering/venv/bin/molecule", line 10, in <module>
    sys.exit(main())
  File "/Users/regreinh/projects/ansible-engineering/venv/lib/python2.7/site-packages/molecule/cli.py", line 68, in main
    CLI().main()
  File "/Users/regreinh/projects/ansible-engineering/venv/lib/python2.7/site-packages/molecule/cli.py", line 64, in main
    sys.exit(c.execute()[0])
  File "/Users/regreinh/projects/ansible-engineering/venv/lib/python2.7/site-packages/molecule/commands.py", line 624, in execute
    '/usr/bin/env ' + login_cmd.format(*login_args),
UnboundLocalError: local variable 'login_cmd' referenced before assignment

Support for multiple test suites

One of the features of Test Kitchen which I love is the ability to define multiple test suites to run against the same Ansible role. There are often many different configurations of the role which need to be tested and I was unable to find (in the documentation, issues, or in the source) a way to accomplish this with Molecule today.

_print_valid_platforms() throws stack trace

molecule status --platform=ubuntu

Invalid platform 'ubuntu'

AVAILABLE PLATFORMS
Traceback (most recent call last):
  File "/usr/local/bin/molecule", line 11, in <module>
    sys.exit(main())
  File "/Library/Python/2.7/site-packages/molecule/cli.py", line 86, in main
    CLI().main()
  File "/Library/Python/2.7/site-packages/molecule/cli.py", line 81, in main
    c = command_class(args)
  File "/Library/Python/2.7/site-packages/molecule/commands.py", line 55, in __init__
    self.molecule.main()
  File "/Library/Python/2.7/site-packages/molecule/core.py", line 75, in main
    self._print_valid_platforms()
  File "/Library/Python/2.7/site-packages/molecule/core.py", line 118, in _print_valid_platforms
    default_platform = self._provisioner.default_platform
AttributeError: 'NoneType' object has no attribute 'default_platform'

Molecule status is too slow (vagrant provider)

The molecule status command, used with the vagrant provider is too slow. It takes an average of 3s to execute. This is particularly annoying as this command is the one providing the dynamic arguments during the bash completion.

Would it be possible to extract the information directly from the molecule configuration file rather than querying vagrant for this?

Ansible inventory doesn't created during converge

Hi, it has been broken with 1.1.1.

$ molecule --version
1.1.1
$ molecule create
Bringing machine 'ansible-role-php-01' up with 'virtualbox' provider...
==> ansible-role-php-01: Importing base box 'bento/centos-6.7'...
==> ansible-role-php-01: Matching MAC address for NAT networking...
==> ansible-role-php-01: Checking if box 'bento/centos-6.7' is up to date...
==> ansible-role-php-01: Setting the name of the VM: ansible-role-php_ansible-role-php-01_1450454874140_66041
==> ansible-role-php-01: Fixed port collision for 22 => 2222. Now on port 2202.
==> ansible-role-php-01: Clearing any previously set network interfaces...
==> ansible-role-php-01: Preparing network interfaces based on configuration...
    ansible-role-php-01: Adapter 1: nat
    ansible-role-php-01: Adapter 2: hostonly
==> ansible-role-php-01: Forwarding ports...
    ansible-role-php-01: 22 => 2202 (adapter 1)
==> ansible-role-php-01: Running 'pre-boot' VM customizations...
==> ansible-role-php-01: Booting VM...
==> ansible-role-php-01: Waiting for machine to boot. This may take a few minutes...
    ansible-role-php-01: SSH address: 127.0.0.1:2202
    ansible-role-php-01: SSH username: vagrant
    ansible-role-php-01: SSH auth method: private key
    ansible-role-php-01: Warning: Connection timeout. Retrying...
    ansible-role-php-01: Warning: Remote connection disconnect. Retrying...
==> ansible-role-php-01: Machine booted and ready!
==> ansible-role-php-01: Checking for guest additions in VM...
==> ansible-role-php-01: Setting hostname...
==> ansible-role-php-01: Configuring and enabling network interfaces...
==> ansible-role-php-01: Mounting shared folders...
    ansible-role-php-01: /vagrant => /Users/bbo/src/gitlab.com/owox-ops-team/ansible-role-php
==> ansible-role-php-01: Machine not provisioned because `--no-provision` is specified.
$ molecule converge
ERROR: Unable to find an inventory file, specify one with -i ?
ERROR:

  RAN: '/Users/bbo/.local/bin/ansible-playbook playbook.yml --inventory-file=.molecule/ansible_inventory --sudo --connection=ssh --limit=all --user=vagrant --timeout=30 --diff'

  STDOUT:


  STDERR:

I suppose due to:

https://github.com/metacloud/molecule/blob/46a6e28/molecule/commands.py#L143

Update python-vagrant to 0.5.10 to support Vagrant 1.8

It seems that python-vagrant should be updated to 0.5.10

With 0.5.9 molecule status command failed due to one more extra item returned by vagrant.status there:

➜  test-role  molecule status
[Status(name='test-role-01', state='running', provider='virtualbox'), Status(name='', state=None, provider=None)]
Traceback (most recent call last):
  File "/Users/bbo/.local/bin/molecule", line 11, in <module>
    sys.exit(main())
  File "/Users/bbo/.local/venvs/molecule/lib/python2.7/site-packages/molecule/cli.py", line 87, in main
    CLI().main()
  File "/Users/bbo/.local/venvs/molecule/lib/python2.7/site-packages/molecule/cli.py", line 83, in main
    sys.exit(method())
  File "/Users/bbo/.local/venvs/molecule/lib/python2.7/site-packages/molecule/commands.py", line 82, in status
    self.commands.status()
  File "/Users/bbo/.local/venvs/molecule/lib/python2.7/site-packages/molecule/commands.py", line 298, in status
    state = Fore.GREEN + item.state + Fore.RESET
TypeError: cannot concatenate 'str' and 'NoneType' objects

With python-vagrant==0.5.10:

➜  test-role  ~/.local/venvs/molecule/bin/pip install python-vagrant==0.5.10
Collecting python-vagrant==0.5.10
Installing collected packages: python-vagrant
  Found existing installation: python-vagrant 0.5.9
    Uninstalling python-vagrant-0.5.9:
      Successfully uninstalled python-vagrant-0.5.9
Successfully installed python-vagrant-0.5.10
➜  test-role  molecule status
[Status(name='test-role-01', state='running', provider='virtualbox')]
+--------------+---------+------------+
| Name         | State   | Provider   |
+--------------+---------+------------+
| test-role-01 | running | virtualbox |
+--------------+---------+------------+

AVAILABLE PLATFORMS
centos-6 (default)

Question: Idempotence Plugin

Hi,

I'm getting this error when I run molecule test and can't figure out what I'm doing wrong:

Idempotence test in progress (can take a few minutes)...
Idempotence test failed.
The idempotence plugin was not found or did not provide the required information. Therefore the failure details cannot be displayed.

I did add the callback from https://github.com/metacloud/molecule/blob/master/assets/ansible/plugins/callback/idempotence/idempotence.py to my top level ansible callback directory, unsure if that should actually be in the role i'm running molecule from or if its some weird ansible version problem?

Anyone hit this before?

Verbose in molecule.yml should handle bool True

https://github.com/metacloud/molecule/blob/master/molecule/ansible_playbook.py#L104

clearly string +bool isn't gonna work. And it will have error like
Traceback (most recent call last):
File "/Users/zochao/.virtualenvs/metamole/bin/molecule", line 10, in <module>
sys.exit(main())
File "/Users/zochao/metamole/molecule/molecule/cli.py", line 66, in main
CLI().main()
File "/Users/zochao/metamole/molecule/molecule/cli.py", line 62, in main
sys.exit(c.execute())
File "/Users/zochao/metamole/molecule/molecule/commands.py", line 393, in execute
c.execute()
File "/Users/zochao/metamole/molecule/molecule/commands.py", line 224, in execute
ansible = AnsiblePlaybook(self.molecule._config.config['ansible'])
File "/Users/zochao/metamole/molecule/molecule/ansible_playbook.py", line 51, in _init_
self.parse_arg(k, v)
File "/Users/zochao/metamole/molecule/molecule/ansible_playbook.py", line 104, in parse_arg
self.cli_pos.append('-' + value)
TypeError: cannot concatenate 'str' and 'bool' objects

Problems with molecule verify(using molecule 1.2.0)

Hi,

I have problems with molecule verify. When I execute molecule test, I get the following output:

Traceback (most recent call last):
File "/home/oscar/project/.venv/bin/molecule", line 11, in <module>
sys.exit(main())
File "/home/oscar/project/.venv/local/lib/python2.7/site-packages/molecule/cli.py", line 87, in main
CLI().main()
File "/home/oscar/project/.venv/local/lib/python2.7/site-packages/molecule/cli.py", line 83, in main
sys.exit(method())
File "/home/oscar/project/.venv/local/lib/python2.7/site-packages/molecule/commands.py", line 76, in test
self.commands.test()
File "/home/oscar/project/.venv/local/lib/python2.7/site-packages/molecule/commands.py", line 284, in test
m()
File "/home/oscar/project/.venv/local/lib/python2.7/site-packages/molecule/commands.py", line 243, in verify
self.molecule._write_ssh_config()
File "/home/oscar/project/.venv/local/lib/python2.7/site-packages/molecule/core.py", line 138, in _write_ssh_config
out = self._vagrant.ssh_config()
File "/home/oscar/project/.venv/local/lib/python2.7/site-packages/vagrant/__init__.py", line 545, in ssh_config
return self._run_vagrant_command(['ssh-config', vm_name])
File "/home/oscar/project/.venv/local/lib/python2.7/site-packages/vagrant/__init__.py", line 883, in _run_vagrant_command
env=self.env, stderr=err_fh))
File "/usr/lib/python2.7/subprocess.py", line 566, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
TypeError: execve() arg 3 contains a non-string value

While molecule test returns that error(note it crashes in the verify part), if I execute all stages separately(molecule create, molecule converge,etc.) everything works properly. I have been checking environment variables, and , even though there are some differences(between executing molecule test and molecule verify separately), I have not been able to find what is causing the problem.

Nevertheless, with other versions of molecule (such as version 1.0.5) I have no issues at all.

Again whitespaces

Hi,

This is from readme example, run on a macbook, molecule version is 1.3.0

$ molecule init foo
$ cd foo
$ molecule test

==> foo-01: Setting hostname...
==> foo-01: Configuring and enabling network interfaces...
==> foo-01: Mounting shared folders...
    foo-01: /vagrant => /Users/rn/devops/molecule/foo
==> foo-01: Machine not provisioned because `--no-provision` is specified.

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [foo-01]

PLAY RECAP *********************************************************************
foo-01                     : ok=1    changed=0    unreachable=0    failed=0

Idempotence test in progress (can take a few minutes)...
Idempotence test passed.
Trailing whitespace found in ./meta/main.yml on lines: 3, 5, 9, 18, 28, 158

If these whitespaces removed, I still don't see serverspec tests running:

molecule verify
============================= test session starts ==============================
platform darwin -- Python 2.7.10, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: /Users/rn/devops/molecule/foo, inifile:
plugins: testinfra-1.0.3
collected 0 items

========================= no tests ran in 0.01 seconds =========================
ERROR:

  RAN: '/Users/rn/virtenv/foobar/bin/testinfra --connection=ansible --sudo --ansible-inventory=.molecule/ansible_inventory'

  STDOUT:

  STDERR:

Python 3 support

It seems molecule only works with python 2.7.
Any chance to support the latest python-version?

Libvirt provider: Molecule destroy does not work well when provider parameters are wrong

Molecule destroy does not work well when libvirt provider parameters are wrong or not supported by the machine.

For instance, when I specify "graphics_type: gtk", i get the following error:

Error while creating domain: Error saving the server: Call to virDomainDefineXML failed: unsupported configuration: unknown graphics device type 'gtk'

Then i execute molecule destroy and nothing happens. If I try to execute molecule again(molecule test, ormolecule create), I get the following error:

Volume for domain is already created. Please run 'vagrant destroy' first.

So while using libvirt and setting wrong or unsupported parameters, I have to remove the volume manually. I do not know whether this happens while using vagrant.

I have observed this section in comands.py:

class Create(AbstractCommand):
    def execute(self):
        """
        Creates all instances defined in molecule.yml.
        Creates all template files used by molecule, vagrant, ansible-playbook.

        :return: None
        """
        if self.static:
            self.disabled('create')

        self.molecule._create_templates()
        try:
            self.molecule._provisioner.up(no_provision=True)
            self.molecule._state['created'] = True
            self.molecule._write_state_file()
        except CalledProcessError as e:
            print('ERROR: {}'.format(e))
            sys.exit(e.returncode)

I would suggest to introduce a vagrant destroy call inside the except block.

VirtualBox: enable promiscuous mode on guests

When standing up OpenStack with molecule + vagrant, it is not possible to pass traffic to VMs, since doing so relies on the network interfaces being set to promiscuous mode, and VirtualBox blocks promiscuous mode on VMs by default.

This can be worked around in the molecule.yml with the following:

raw_config_args:
  - "vm.provider :virtualbox do |vb| vb.customize ['modifyvm', :id, '--nicpromisc1', 'allow-all', '--nicpromisc2', 'allow-all', '--nicpromisc3', 'allow-all'] end"

...but the VirtualBox provider should set that on all guests by default.

Move off the Vagrant OpenStack provider

Supporting multiple providers will become fairly cumbersome inside the Vagrantfile. We need to error on the side of simplicity, and keep the Vagrantfile as simple as possible.

This issue is to move the OpenStack provider out of Vagrant, and into a pure Ansible playbook leveraging OpenStack.

linting/validators

There has been much discussion and some code concerning validators/linting with divergent opinions, I'm opening this issue as a place to collect opinions about the direction we want to take in the area of validation. Please add your thoughts below and whether you will be able to dedicate time to developing.

It seems that the most sensible compromise would be to support molecule options such that the user's molecule config would contain a list of validators (for which molecule would provide sensible defaults such as those we have now) and allow the command line invocation of molecule to override.

It would be extra nice if the invocation could also support severity signalling (see http://search.cpan.org/~thaljef/Perl-Critic-1.126/bin/perlcritic for an example) with various levels such as:
--validation=False|off|none
--validation=basic
--validation=all

for which each validator's config in the molecule.yml would have an interpretation.

The obvious initial candidates for initially supported validators are:

  • ansible-lint for playbooks
  • yapf/flake8 for python files
  • rubocop for (serverspec) ruby files

Testinfra ssh

Hi, I think there is an issue in core.py. When using testinfra, tests are not executed on the vagrant machine, because when calling testinfra no hosts are specified. So tests are executed on the host machine.

Install role dependencies with ansible-galaxy?

Hi,

Could you please give piece of advice about the right way to test ansible role that has some dependencies with molecule? For the moment I use a bit different directory layout and override some molecule defaults:

$ tree .
...
├── tests
│   ├── playbook.yml       <-- playbook to execute during `molecule converge`
│   ├── requirements.yml   <-- requirements for `ansible-galaxy`
│   ├── roles              <-- extra roles installed with `ansible-galaxy`
│   │   └── yum-epel
│   │   └── ...
│   ├── serverspec         <-- `serverspec_dir`
│   │   └── ...
...

$ cat molecule.yml

---
molecule:
  serverspec_dir: tests/serverspec
  testinfra_dir: tests/testinfra
  ansible_config_template: /Users/bbo/.config/molecule/ansible.cfg.j2
ansible:
    playbook: tests/playbook.yml
...

$ cat /Users/bbo/.config/molecule/ansible.cfg.j2
[defaults]

roles_path = tests/roles:../
library    = library

And before molecule converge I manually run:

ansible-galaxy install -r tests/requirements.yml -p tests/roles

But I guess that it should be some better way to do it. It will be great to have configuration option with path to a file with requirements for ansible-galaxy and install them automatically before molecule converge.

1.1.2 - molecule verify gives ruby ssh error

This is relevant to the conversion from pre-1.0 molecule to 1.1.2, I have been re-writing molecule_playbook.yml into molecule.yml and playbook.yml. I also removed the old .molecule and Vagrant files to clean up. With the update to 1.1.2 I am now getting the included error, yet molecule login works fine. Not sure where the problem exists.

*** Run serverspec on vagrant1-ubuntu instance ***
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -I/Library/Ruby/Gems/2.0.0/gems/rspec-support-3.3.0/lib:/Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/lib /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/exe/rspec --pattern spec/_spec.rb,spec/vagrant1/_spec.rb,spec/hosts/vagrant1/_spec.rb
/Library/Ruby/Gems/2.0.0/gems/net-ssh-2.9.2/lib/net/ssh.rb:224:in start': Authentication failed for user [email protected] (Net::SSH::AuthenticationFailed) from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/backend/ssh.rb:76:increate_ssh'
from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/backend/ssh.rb:110:in ssh_exec!' from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/backend/ssh.rb:17:inblock in run_command'
from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/backend/ssh.rb:67:in with_env' from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/backend/ssh.rb:16:inrun_command'
from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/helper/detect_os.rb:13:in run_command' from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/helper/detect_os/suse.rb:3:indetect'
from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/helper/detect_os.rb:5:in detect' from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/helper/os.rb:24:inblock in detect_os'
from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/helper/os.rb:23:in each' from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/helper/os.rb:23:indetect_os'
from /Library/Ruby/Gems/2.0.0/gems/specinfra-2.44.1/lib/specinfra/helper/os.rb:9:in os' from /Users/brmathes/git/ansible-systems/roles/cisco.metacloud_build.configure_spine/spec/default_spec.rb:3:in<top (required)>'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:in load' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1327:inblock in load_spec_files'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:in each' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/configuration.rb:1325:inload_spec_files'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:102:in setup' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:88:inrun'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:73:in run' from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/lib/rspec/core/runner.rb:41:ininvoke'
from /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/exe/rspec:4:in `

'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -I/Library/Ruby/Gems/2.0.0/gems/rspec-support-3.3.0/lib:/Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/lib /Library/Ruby/Gems/2.0.0/gems/rspec-core-3.3.2/exe/rspec --pattern spec/
_spec.rb,spec/vagrant1/_spec.rb,spec/hosts/vagrant1/_spec.rb failed
ERROR:

RAN: '/usr/bin/rake --rakefile=.molecule/rakefile'
'''

Idempotence test fails if ansible_managed is used

I prefer to add ansible_managed at the top of any template inside my roles. But since by default it includes time stamps, idempotence test fails most times. For the moment I just use a custom ansible.cfg with own ansible_managed. But it forced me to add ansible.cfg to each role, and I feel like that is not the best solution.

The other way is to use a DEFAULT_ROLES_PATH environment variable and add it to raw_env_vars sections of molecule.yml. Well it's a better, but still forced me to keep in mind to add this line to molecule config of each role.

What are you thinking about adding to default ansible.cfg.j2 template something like (without time stamps):

ansible_managed = Ansible managed

Other way is add some addition setting to molecule.yml.j2, but I guess that it's not likely that someone really needs to override it. There are no more use cases to override it as far I know.

100 chars is too short for spec files

I have paths and other tests that end up being longer than 100 characters. For instance
'''
pec/entity_spec.rb:68:100: C: Line is too long. [116/99]
describe file('/ xxx/xxxxx/xxxxxx/xxxx_xx/xxxx/xxx/xxxxxx/xxx/xxxxxxxx-xx/ssl/xxxxxxxx.xxxxxxxxxx.xx.xxxxxxxxx.xx.crt') do
^^^^^^^^^^^^^^^^^
spec/entity_spec.rb:72:100: C: Line is too long. [100/99]
its(:content) { should match(/MIIxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/) }
'''
Need to up that to twitter spec at least (140 chars ;)

[v1.4.1] Testing multiple roles

Hi,

I'm having a test project with "tests" folders in different roles and one in the root folder. When I run molecule verify in version 1.4.0 it says:

Executing testinfra tests found in tests/.
============================= test session starts ==============================
platform darwin -- Python 2.7.9, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: /Users/skornehl/workspace/ansible-intro, inifile: 
plugins: testinfra-1.1.1
collected 21 items 

roles/httpd/tests/httpd_test.py ......

in version 1.4.1 i only get:

Executing testinfra tests found in tests/.
============================= test session starts ==============================
platform darwin -- Python 2.7.9, pytest-2.9.1, py-1.4.31, pluggy-0.3.1
rootdir: /Users/skornehl/workspace/ansible-intro/tests, inifile: 
plugins: testinfra-1.1.1
collected 0 items 

My tree looks like this:

├── molecule.yml
├── roles
│   ├── httpd
│   │   ├── tasks
│   │   │   └── main.yml
│   │   └── tests
│   │       └── httpd_test.py
├── site.yml
├── stage
└── tests

Also: I need an empty test folder in the root directory to make molecule use the folders in the roles, too.

Ability to merge in existing group_vars?

First, hey guys, glad to see ansible is working out @dhutty !

I stumbled over this today and decided to play around with it, but quickly ran into a problem. The problem is almost none of my roles is standalone, and they all require a playbook called all.yml to be run first (to setup docker, etc).

That playbook really, really, wants group_vars/all/ available in the ansible-playbook run because I define a bunch of variables there, rather than having sensible defaults in all the roles because I'm in a rush (as always) and a bad person.

I'm not familiar enough with this code to hack it in so I thought I'd see if anyone here has a suggestion on the easiest way to get that to work.

`molecule test` interrupted if one of step failed.

Just realized that actually it's not possible to use just molecule test on CI environment. Since we use sys.exit here and here, if converge or verify step is failed we stuck with a VM that need to be destroed manually.

As workaround I run molecule on CI server like this:

molecule test || molecule destroy

But it will be great if molecule will take care about that point itself.

Support multiple simultaneous logins with cluster-ssh

I have a small shell script that I use to login to multiple vagrant VMs simultaneously using csshX; perhaps molecule could investigate the system for the presence of such tools and do something similar if no <host> parameter is provided to molecule login:

#!/bin/sh

: init
PROGNAME=`basename $0`
TMPFILE=`mktemp -t $PROGNAME`
trap 'rm -f $TMPFILE' EXIT 
vagrant ssh-config > $TMPFILE
CSSH="csshX --ssh_args='-A -F $TMPFILE'"

: enumerate
CONTROLLERS=`awk '($1 == "Host" && $NF ~ /^controller/) { print $NF }' $TMPFILE`
COMPUTE_NODES=`awk '($1 == "Host" && $NF ~ /^compute/) { print $NF }' $TMPFILE`

# invocation is "controller", "compute", or "all"
case "$1" in
    all)
        eval $CSSH ${CONTROLLERS} ${COMPUTE_NODES} ;;
    con*)
        eval $CSSH ${CONTROLLERS} ;;
    *)
        eval $CSSH ${COMPUTE_NODES} ;;
esac

Errors are displayed on stdout

Errors are displayed on the standard output stream instead of the standard error stream. This causes issues when using redirections. For instance adding 2>/dev/null at the end of a command has no effect.

A use case where this is really annoying is with the bash completion. The bash completion scripts relies on the molecule status command to provide the dynamic arguments. If an error occurs, it will also be displayed in stdout and therefore pollute the completion.

An idea to solve this would be to use the logging library to display (at least) errors instead of print(), as the default logging output for errors is sys.stderr.

Don't lint template/ files/ dirs

We lint the entire role, which we probably shouldn't do. Sure trailing white spaces and new lines suck, and should't exist in the ansible yml files, but there may be valid cases for them in the artifacts ansible creates.

Lets not lint templates/ and files/ dir, or maybe we only lint files that end in yml?

Feature idea: Add a new molecule command to perform a syntax check

IDEA: Add a new molecule command to run ansible-playbook locally with --syntax-check option. Something like:

ANSIBLE_CONFIG=.molecule/ansible.cfg ansible-playbook playbook.yml --inventory-file='localhost,' --connection=local --syntax-check

Change sequence of commands to run when performing molecule test to

  test:
    # sequence of commands to run when performing `molecule test`
    sequence:
      - destroy
      - syntax-check
      - create

The main goal is to fail as soon as possible.

NOTE: #105 then should go from converge step to syntax-check

Question: accessing values of variables as they are being used for provisioning an instance inside Testinfra tests

I want to use Testinfra tests to test my role.

Inside an Testinfra test I would like to access the values of variables as they are being used for provisioning the machine when playbook.yml is converged for some instance.
I need this since the instance's state, which I want to check, depends on the chosen values of the variables defined in role's default/main.yml or vars/main.yml file.

I tried using the following 'trick' suggested by Testinfra maintainer, but it only works for Ansible facts and group_vars/host_vars, not for variables defined within a role, either in default/main.yml or vars/main.yml.

Here is an example test for PostgreSQL service:

def test_postgresql_running_and_enabled(Ansible, Service):
    postgresql_unit_name = Ansible("debug", "msg={{ postgresql_unit_name }}")["msg"]
    postgresql = Service(postgresql_unit_name)
    assert postgresql.is_running
    assert postgresql.is_enabled

Variable postgresql_unit_name is defined in role's vars/main.yml, but apparently the invocation of Ansible through Testinfra is unable to find it. Here is the error:

    def test_postgresql_running_and_enabled(Ansible, Service):
        postgresql_unit_name = Ansible("debug", "msg={{ postgresql_unit_name }}")["msg"]
        postgresql = Service(postgresql_unit_name)
>       assert postgresql.is_running
E       assert <service 'postgresql_unit_name' is undefined>.is_running

Any ideas how I could achieve this?

`molecule login` should infer single host

When running molecule login, it requires a hostname, even if there's only one host running. If there's only one host running, molecule login should not require a hostname, and should assume that the only running machine is the SSH target.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.