Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ansible with with Molecule
Search
Markus Hanses
February 28, 2019
Programming
94
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
2k
Apache Zeppelin Tutorial
markushanses
0
470
Git - shared insights
markushanses
0
91
Spock configuration variants
markushanses
0
330
Spock.Code.Week
markushanses
0
130
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
作るコストが小さくなった時代 幸せに働くために改めて考えたいこと 〜エンジニアとして価値を出し続けるために注視している二分野〜
yuppeeng
0
180
AI時代、エンジニアはどう育つのか -未経験エンジニアの成長を間近で見て考えたこと-
thasu0123
0
210
複数の Claude Code が"放置"されてしまう問題をCLI ダッシュボードを自作して解決した話
sumihiro3
1
640
<title><a id="</title>君はこのHTMLをパースできるか"></a></title> #雑LT_study
pizzacat83
0
130
ここ半年くらいでAIに作らせたR用ツール
eitsupi
0
360
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
130
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
140
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
4
1.8k
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
3.4k
freee が目指す データ マネジメント戦略 AI-Ready 時代を支える 攻めのガバナンスとは
freee
PRO
0
230
言語を使う側から、作る側へ。 自作 Lisp で得た新たな気づき。
andpad
0
150
テーブルをDELETEした
yuzneri
0
130
Featured
See All Featured
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
480
Building Flexible Design Systems
yeseniaperezcruz
330
40k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
690
Paper Plane
katiecoart
PRO
2
52k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
340
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
470
Between Models and Reality
mayunak
4
380
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
Producing Creativity
orderedlist
PRO
348
40k
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