Skip to content

Commit

Permalink
Testing role details. Also added diagram of TDD infra cycle
Browse files Browse the repository at this point in the history
  • Loading branch information
jonashackt committed Nov 22, 2018
1 parent 8da5846 commit 3da8a05
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ hs_err_pid*
.idea

.molecule

venv
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# molecule-ansible-vagrant
Example project showing how to test Ansible roles with Molecule and Vagrant

### TDD for Infrastructure code with Molecule!

![tdd-for-iac](https://yuml.me/diagram/scruffy/class/[Given:%20Spin%20up%20Infrastructure%20with%20Vagrant]->[Then:%20Execute%20Ansible%20Playbooks/Roles],[Then:%20Execute%20Ansible%20Playbooks/Roles]->[Then:%20Assert%20with%20Testinfra],[Then:%20Assert%20with%20Testinfra]->[Cleanup%20Infrastructure])


### Prerequisites

Expand All @@ -13,17 +17,18 @@ Example project showing how to test Ansible roles with Molecule and Vagrant
* `brew cask install vagrant`
* `brew install molecule`

### Let´s go

### How to

Execute:

`molecule init --driver vagrant --role install-docker --verifier testinfra`
`molecule init --driver vagrant --role docker --verifier testinfra`

this will give:

`--> Initializing role install-docker...
Successfully initialized new role in /Users/jonashecht/dev/molecule-ansible-vagrant/install-docker.`
`--> Initializing role docker...
Successfully initialized new role in /Users/jonashecht/dev/molecule-ansible-vagrant/docker.`

Now we´re able to run our first test. Go into `install-docker` directory and run:
Now we´re able to run our first test. Go into `docker` directory and run:

`molecule test`
12 changes: 7 additions & 5 deletions docker/tests/test_default.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
'.molecule/ansible_inventory').get_hosts('all')


def test_hosts_file(host):
f = host.file('/etc/hosts')
def test_is_docker_installed(host):
package_docker = host.package("docker")
assert package_docker.is_installed

assert f.exists
assert f.user == 'root'
assert f.group == 'root'

def test_vagrant_user_is_part_of_group_docker(host):
user_vagrant = host.user("vagrant")
assert user_vagrant.group == 'docker'

0 comments on commit 3da8a05

Please sign in to comment.