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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Markus Hanses
February 28, 2019
Programming
93
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
460
Git - shared insights
markushanses
0
89
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
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
210
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
2.2k
ビデオ通話が繋がる0.2秒で何が起きているのか
supurazako
2
120
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
220
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
5.5k
Hatena Engineer Seminar #37「言語モデルの活用に関する研究」
slashnephy
0
500
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
12
4.7k
LLMによるContent Moderationの本番運用の裏側と品質担保への挑戦
suikabar
3
840
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
260
継続モナドとリアクティブプログラミング
yukikurage
3
470
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
1
160
1B+ /day規模のログを管理する技術
broadleaf
0
130
Featured
See All Featured
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.7k
KATA
mclloyd
PRO
35
15k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.2k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4.1k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
190
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
630
How to make the Groovebox
asonas
2
2.3k
Crafting Experiences
bethany
1
210
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
1
2.1k
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