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
290
今インフラ技術をイチから学び直すなら
yuhta28
1
300
AWSに詳しくない人でも始められるコスト最適化ガイド
yuhta28
3
680
Datadog外形監視基盤をEC2から ECSへ移行してみた
yuhta28
0
1.8k
アウトプット頑張ったら企業からLT登壇の依頼がきた話
yuhta28
1
1.8k
小さなことから始めるAWSコスト最適入門
yuhta28
1
1.4k
Datadogのコストも監視しよう
yuhta28
1
1.1k
Rcloneを使った定期的なストレージ同期
yuhta28
0
830
Pulumiを触ってみよう
yuhta28
1
2.7k
Other Decks in Programming
See All in Programming
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
5.8k
Creating Composable Callables in Contemporary C++
rollbear
0
130
3Dシーンの圧縮
fadis
1
770
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
170
脅威をエンジニアリングの糧にして――現場編 / Turning Threats into Engineering Fuel — Field Edition
nrslib
0
280
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
170
The ROI of Quarkus for Spring Boot Applications
hollycummins
0
120
ローカルLLMでどこまでコードが書けるか -拡張版 / How much code can be written on a local LLM Extended
kishida
10
4k
New "Type" system on PicoRuby
pocke
1
920
Vite+ Unified Toolchain for the Web
naokihaba
0
300
TAKTでAI駆動開発の品質を設計する
j5ik2o
6
1.3k
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
230
Featured
See All Featured
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Building an army of robots
kneath
306
46k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Navigating Weather and Climate Data
rabernat
0
220
Building Experiences: Design Systems, User Experience, and Full Site Editing
marktimemedia
0
530
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
Odyssey Design
rkendrick25
PRO
2
700
Side Projects
sachag
455
43k
Unsuck your backbone
ammeep
672
58k
Color Theory Basics | Prateek | Gurzu
gurzu
0
360
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
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