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 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
300
今インフラ技術をイチから学び直すなら
yuhta28
1
310
AWSに詳しくない人でも始められるコスト最適化ガイド
yuhta28
3
680
Datadog外形監視基盤をEC2から ECSへ移行してみた
yuhta28
0
1.8k
アウトプット頑張ったら企業からLT登壇の依頼がきた話
yuhta28
1
1.9k
小さなことから始めるAWSコスト最適入門
yuhta28
1
1.4k
Datadogのコストも監視しよう
yuhta28
1
1.1k
Rcloneを使った定期的なストレージ同期
yuhta28
0
850
Pulumiを触ってみよう
yuhta28
1
2.7k
Other Decks in Programming
See All in Programming
フィードバックで育てるAI開発
kotaminato
1
120
ルールを書いて終わらせないハーネスエンジニアリング
yug1224
3
1.6k
act1-costs.pdf
sumedhbala
0
240
『コードを書く以外の』エンジニアリング〜課金基盤移行プロジェクト推進のためのTips4選
yuriko1211
0
520
AI がコードを書く時代における新卒エンジニアの仕事風景 (2026) / New Graduate Engineers in the Era of AI Coding (2026)
sushichan044
0
220
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
120
PHP Application における Kubernetes 内 gRPC 通信
ganchiku
0
510
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.5k
Apache Hive: Toward a Cloud Native Lakehouse
okumin
0
140
霧の中の代数的エフェクト
funnyycat
1
410
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
170
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
110
Featured
See All Featured
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
62
45k
VelocityConf: Rendering Performance Case Studies
addyosmani
333
25k
It's Worth the Effort
3n
188
29k
GitHub's CSS Performance
jonrohan
1033
470k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
350
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.7k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
770
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
260
GraphQLとの向き合い方2022年版
quramy
50
15k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
410
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
320
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