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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Markus Hanses
February 28, 2019
Programming
95
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
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
Webエンジニアなのにブラウザの仕組みがわからないので、Pythonで自作してみた
tatsuki12
4
1k
実装をデザインガイドラインに追従させるための取り組み / 260731-dip-mosh-design-system
dachi023
0
7.8k
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.7k
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
170
仕様書を書く前にハーネスを作る - Agent Native開発は「探索を速く、判定を固く」
gotalab555
4
1.8k
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
720
ソフトウェアエンジニアにとっての生成AI - 特性を知って使い倒す / generative ai for software enginner
kishida
7
2.1k
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
380
ドリフトを絶対に許さない(?)CDK運用 / CDK Ops with Zero Tolerance for Drifts (?)
akihisaikeda
1
220
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
350
属人化した知識を、 AIが辿れる地図にする
pkshadeck
PRO
1
200
異なる設計思想のフレームワークを経験して得た学び
amekuhideki
1
420
Featured
See All Featured
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
630
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
250
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
480
A Soul's Torment
seathinner
6
3.5k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
470
The Spectacular Lies of Maps
axbom
PRO
1
940
Navigating Team Friction
lara
192
16k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
210
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Faster Mobile Websites
deanohume
310
32k
Unsuck your backbone
ammeep
672
58k
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