Create a new ansible role

Create a new ansible role#

Please use the ansible role cookiecutter to template a new role.


If you are developing new ansible roles for computational materials science applications and would like to make them easier to find, we’d be happy to host them under the marvel-nccr github organisation - just drop us a line.

Testing a role#


The simplest way to test a role is to:

Clone its repository into your roles folder, e.g.

git clone roles/marvel-nccr.simulationbase

Add your role to the playbook.yml file with a tag:

- role: marvel-nccr.simulationbase
  tags: [simulationbase]
    simulationbase_vm_user: "{{ vm_user }}"
    simulationbase_vm_user_public_key: "{{ lookup('file', './keys/') }}"
    simulationbase_hostname: "{{ vm_hostname }}"
    simulationbase_codes_folder: "{{ vm_codes_folder }}"

Run the role on your existing VM (e.g. Quantum Mobile):

ansible-playbook.yml --tags simulationbase

Continuous Integration#

Both existing marvel-nccr roles on ansible galaxy and those templated via the cookiecutter come with a few tools to help you test the roles individually. In the git repository of the role:

  • use the pre-commit hooks to lint your yaml files:

    pip install -r requirements.txt
    pre-commit install

    From now on, lints on every commit.

  • install Docker and use molecule for a full test of your role:

    pip install -r requirements.txt
    molecule tests

    This will first run the linters and then run your role on a docker container (which is thrown away after the test). It actually runs your role twice to make sure it’s idempotent.