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 MoleculeとGitHub ActionsでCI_CDを体験してみた
Search
YouYou
December 05, 2020
Programming
2.1k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Ansible MoleculeとGitHub ActionsでCI_CDを体験してみた
ブログURL↓
https://zenn.dev/yuta28/articles/033efeb622a45cf44c91
YouYou
December 05, 2020
More Decks by YouYou
See All by YouYou
AWSマネコンに複数のアカウントで入れるようになりました
yuhta28
2
310
今インフラ技術をイチから学び直すなら
yuhta28
1
310
AWSに詳しくない人でも始められるコスト最適化ガイド
yuhta28
3
690
Datadog外形監視基盤をEC2から ECSへ移行してみた
yuhta28
0
1.9k
アウトプット頑張ったら企業からLT登壇の依頼がきた話
yuhta28
1
1.9k
小さなことから始めるAWSコスト最適入門
yuhta28
1
1.5k
Datadogのコストも監視しよう
yuhta28
1
1.1k
Rcloneを使った定期的なストレージ同期
yuhta28
0
880
Pulumiを触ってみよう
yuhta28
1
2.8k
Other Decks in Programming
See All in Programming
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
130
すこし踏み込む CancellationToken
htkym
1
480
動作中のプログラムの中身をリアルタイムに覗く / Realtime Debugger for CSharp with Roslyn
prota
1
430
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
150
Intent as Code
shoppingjaws
6
1k
Heart of Swift Concurrency
koher
0
890
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.8k
世界の中心で、AI(App Intents)をさけぶ ー App Intents中心設計の実践ガイド
touyou
0
610
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
250
変化を抱擁するドキュメントの作り方 - ビジネスルール駆動開発がもたらす、コードとの新しい関係
ioki
2
210
[GoCon2026] When Goroutines Are Not Enough: Runtime Locality in High-Throughput Go
takehaya
6
2.3k
AWS DevOps Agentで インシデント対応をAIに任せたい
honmarkhunt
7
3k
Featured
See All Featured
Embracing the Ebb and Flow
colly
88
5.2k
[SF Ruby Conf 2025] Rails X
palkan
3
1.4k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
700
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
320
Gemini Prompt Engineering: Practical Techniques for Tangible AI Outcomes
mfonobong
2
530
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
ラッコキーワード サービス紹介資料
rakko
1
4.9M
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Paper Plane
katiecoart
PRO
4
53k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
240
Transcript
Ansible MoleculeとGitHub ActionsでCI/CDを体験してみた
Name:ユータ Occupation:SRE Twitter:@Y0u281 (オーでなくゼロです) ブログ:https://zenn.dev/yuta28 → 普段触るもの:AWS Ansible Linux Mint
自己紹介 Twitter
発表の前に… • 話すこと ◦ MolecueとGitHub Actionsのチュートリアル体験 ◦ 雑誌で紹介されている内容の体験 ◦ それぞれのツールの(初心者なりの)説明
◦ 公式ドキュメントで躓いた経験 • 話さないこと ◦ 上級者的なこと ◦ 明日から業務で役立てるTIPS
目次 • 背景 • やったこと • イメージ図 • Ansible Moleculeとは
• GitHub Actionsとは • 実装 • 躓いたこと • 感想
背景 • Ansible Roleは一度作成しても、度々修正する必要がある • 修正後にテストを行って、動作確認する必要がある ◦ 修正の度にテストは面倒 • テストフレームワークを使ってテストを簡単にしたい
• GitHub Actionsを使ってテストもCI/CDに✨
やったこと • テスト環境としてCentOS7,CentOS8のコンテナを用意(molecule.yml) • テスト対象のタスクPlaybookを用意 (Software Design 2020年6月号|技術評論社) • molecule
testでタスクがPlaybookが問題なく動くことを確認 • GitHub Actionsをリポジトリ内に組み込む • GitHub Actionsの仮想環境でMoleculeを実行
イメージ図
Ansible Moleculeとは • Ansible Roleをテスト支援するフレームワーク(https://molecule.readthedocs.io/en/latest/) • 最新安定とその一個前のAnsibleに対応している 時点で と •
シナリオベースで一連の処理をテストする
GitHub Actionsとは • GitHub社が提供するCI/CDシステム(https://github.co.jp/features/actions) • GitHubに関係する操作なども自動化できる • パブリックリポジトリでの利用は無料 プラン ジョブ実行時間
ストレージ Free 2,000分/月 500MB Pro 3,000分/月 1GB Team 3,000分/月 2GB Enterprise Cloud 50,000分/月 50GB
実装(Ansible Molecule編) molecule.yml --- dependency: name: galaxy driver: name: docker
platforms: - name: instance1 image: docker.io/centos:7 pre_build_image: true privileged: True command: /sbin/init - name: instance2 image: docker.io/centos:8 pre_build_image: true privileged: True command: /sbin/init provisioner: name: ansible verifier: name: ansible main.yml --- # tasks file for testmol - name: install httpd package yum: name: httpd state: latest - name: start httpd systemd: name: httpd state: started enabled: yes verify.yml --- # This is httpd install playbook to execute Ansible tests. - name: Verify hosts: all tasks: - ignore_errors: yes block: - name: httpdパッケージの存在を確認する yum: list: httpd register: result_rpm - name: httpdプロセスが起動していることを確認する shell: ps -ef | grep http[d] register: result_proc - name: httpdサービスが自動起動になっているかを確認する shell: systemctl is-enabled httpd register: result_enabled - name: 結果をまとめて確認する assert: that: "{{ result.failed == false }}" loop: - "{{ result_rpm }}" - "{{ result_proc }}" - "{{ result_enabled }}" loop_control: loop_var: result
実装(Ansible Molecule編) • molecule testコマンドを実行(長いので結果だけ) • テスト完了後にテスト環境を削除するアクションを自動で行う(destroy) PLAY RECAP *********************************************************************
instance1 : ok=5 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 instance2 : ok=5 changed=2 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 Verifier completed successfully. --> Scenario: 'default' --> Action: 'cleanup' Skipping, cleanup playbook not configured. --> Scenario: 'default' --> Action: 'destroy' PLAY [Destroy] *****************************************************************
実装(GitHub Actions編)
実装(GitHub Actions編) --- name: Molecule Test on: [push, pull_request] jobs:
build: runs-on: ubuntu-latest strategy: max-parallel: 4 matrix: python-version: [3.7, 3.8] steps: - uses: actions/checkout@v2 with: path: molecule_demo - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | sudo apt install git apt-transport-https ca-certificates curl gnupg-agent software-properties-common curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" sudo apt-get update sudo apt-get install docker-ce docker-ce-cli containerd.io git clone https://github.com/Yuhta28/ansible-Molecule.git python3 -m pip install --upgrade pip python3 -m pip install -r ansible-Molecule/requirements.txt python3 -m pip install "molecule[docker,lint]" - name: Test with molecule run: | cd ansible-Molecule/testmol molecule test • job ◦ ワークフローの中の構成要素 ◦ 複数のjobを並列して実行も可能 • step ◦ jobの中の構成要素 ◦ コマンドの実行内容 • runner ◦ jobの実行環境(WinS Mac Ubuntuが対応) 詳しい内容は公式のリファレンスを⇓ https://docs.github.com/ja/free-pro-team@latest/actions/learn-github-actions/introduction-to-gi thub-actions 実行環境 処理内容
実装(GitHub Actions編) 失敗したらこうなるよ
躓いたこと • Ansilbe Moleculeの公式リファレンスで紹介されていたサンプルで失敗 • 紹介されているDockerコンテナのインストール方法がおかしい --- name: Molecule Test
on: [push, pull_request] jobs: build: runs-on: ubuntu-latest strategy: max-parallel: 4 matrix: python-version: [3.6, 3.7] steps: - uses: actions/checkout@v2 with: path: molecule_demo - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | sudo apt install docker python3 -m pip install --upgrade pip python3 -m pip install -r requirements.txt - name: Test with molecule run: | molecule test Ubuntuでこんなインストール方法は知らない https://docs.docker.com/engine/install/ubuntu/
まとめ
ありがとうございました より詳しい内容は私のブログで⇓ Ansible MoleculeとGitHub ActionsでCI/CDを体験してみた https://zenn.dev/yuta28/articles/033efeb622a45cf44c91