Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Ansible with with Molecule
Search
Markus Hanses
February 28, 2019
Programming
99
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ansible with with Molecule
Markus Hanses
February 28, 2019
More Decks by Markus Hanses
See All by Markus Hanses
DomainDriven Design - An Overview
markushanses
0
2.1k
Apache Zeppelin Tutorial
markushanses
0
480
Git - shared insights
markushanses
0
91
Spock configuration variants
markushanses
0
340
Spock.Code.Week
markushanses
0
140
Kontinuierliches Refactoring
markushanses
0
1.1k
TDD Coding Dojo
markushanses
0
630
TDD Code-Kata - Eine Einführung
markushanses
0
580
Other Decks in Programming
See All in Programming
Can LLMs Replicate 4 Years of Compose Migration? Exploring the boundaries of automation with 279 XML files from a real product
makun
0
130
kubernetes コンポーネント開発入門 / 新卒N年目の勉強会&交流会!〜〇〇への誘い〜 #n_study
mazrean
0
220
go-spidermonkeyでAIエージェントのCode Modeを実装する
syumai
3
1.5k
アクセシビリティから考える情報設計
high_g_engineer
0
360
週末にAI-DLCを本気で回したら$1,600溶けた
hbashimizu
0
130
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
140
From 6 People Classroom Meetup to 100 People Regional Conference / FOSS4G Hiroshima 2026
furukawayasuto
0
140
AI × TiDD / 2026.09.05 Redmine 大阪
tokudiro
1
130
[DroidKaigi 2026] Bring your own phones to Gradle Managed Devices
f2lk
0
120
Deep dive into the select statement (GopherCon UK)
jespino
0
180
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
440
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
120
Featured
See All Featured
Building Applications with DynamoDB
mza
96
7.2k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
For a Future-Friendly Web
brad_frost
183
10k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
830
Tell your own story through comics
letsgokoyo
1
1.1k
Building Adaptive Systems
keathley
44
3.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Reality Check: Gamification 10 Years Later
codingconduct
0
2.3k
Done Done
chrislema
186
16k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
420
Transcript
Ansible Testing with Molecule
Advantages • Quality gate for Infrastructure as Code • Isolated
test environment • Early feedback during development • Fail fast before application in real systems • Encourages separation of concerns in Ansible Roles
Python setup with pyenv
Create your Environment $> virtualenv project/venv # creates env $>
source project/venv/bin/activate # activates env $> deactivate # deactivates env
Install Molecule $> pip install molecule ansible $> pip docker
# virtualization driver
Create new Ansible role $> molecule init role --role-name user.rolename
-d docker $> molecule init role -r user.rolename -d docker # choose driver from one below... # azure, docker, ec2, gce, lxc, lxd, openstack, vagrant, # delegated
Add Molecule to existing Ansible role $> ansible-galaxy init user.rolename
$> cd user.rolename $> molecule init scenario -r user.rolename
Add new scenarios to Molecule $> molecule init scenario \
# long --scenario-name special \ -r user.rolename $> molecule init scenario \ # short -s special \ -r user.rolename
Molecule configurations • Test run ◦ molecule.yml # Molecule configuration
file ◦ playbook.yml # Test case definition • Syntax checks ◦ yamllint # Linter for Yaml files / Ansible, Molecole ◦ flake8 # Linter for Python code / Testinfra ◦ ansible-lint # Linter for Ansible playbooks
Molecule test run $> molecule test # bare metal $>
docker run --rm -it \ # docker -v '$(pwd)':/tmp/$(basename "${PWD}"):ro \ -v /var/run/docker.sock:/var/run/docker.sock \ -w /tmp/$(basename "${PWD}") \ retr0h/molecule:latest \ sudo molecule test
Molecule test matrix └── default ├── lint # flake8, yamllint,
ansible-lint syntax check ├── destroy # deletes pre-existing containers ├── dependency # installs python dependencies ├── syntax # Playbook syntax check ├── create # creates the docker container ├── prepare # prepares the docker container / pre-configuration ├── converge # executes the test playbook ├── idempotence # executes the test playbook a second time ├── side_effect # Occurs additional effects to the environment ├── verify # executes the Testinfra tests └── destroy # deletes new containers
Demo Time • IaC sample project • From scratch
end of presentation Author Markus Hanses Date 2019-03-02
Sources • pyenv, https://github.com/pyenv/pyenv • Virtualenv, https://docs.python-guide.org/dev/virtualenvs/ • Molecule, https://molecule.readthedocs.io/en/latest/index.html
• Testinfra, https://testinfra.readthedocs.io/en/latest/# • flake8, http://flake8.pycqa.org/en/latest/ • yamllint, https://yamllint.readthedocs.io/en/stable/ • ansible-lint, https://github.com/ansible/ansible-lint • Digital Ocean Blog Post, http://bit.do/eJXD3 • Demo project, https://github.com/marhan/ansible-role-fail2ban • Demo pipeline, https://travis-ci.org/marhan/ansible-role-fail2ban