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
320
今インフラ技術をイチから学び直すなら
yuhta28
1
320
AWSに詳しくない人でも始められるコスト最適化ガイド
yuhta28
3
700
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
setup-vp GitLab対応の裏側
naokihaba
0
140
iOSDC Japan 2026 - Swiftで作って学ぼう!データベース自作入門
kaseken
2
410
一人だけ、Kiroが静止する日
hideg
0
140
AWS CDKのカスタムリソースでContinuum(旧Security Agent)を実装した話 | Implementing Continuum (formerly Security Agent) via AWS CDK Custom Resource
akihisaikeda
1
110
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
800
The Rails Doctrine Decade
koic
2
440
AWSに止められる覚悟してますか?
morizo_1984
2
490
GitHubハンズオン講座 — 実務レベルのチーム開発のフローを身につけよう
junhat6
0
110
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
380
Simple Storage Service(S3) is not simple
iwatsukayura
0
110
Webの地図
yosuke_furukawa
PRO
6
5k
Intent as Code
shoppingjaws
6
1.1k
Featured
See All Featured
[RailsConf 2023] Rails as a piece of cake
palkan
59
7k
The Pragmatic Product Professional
lauravandoore
37
7.5k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
3.2k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Marketing to machines
jonoalderson
1
5.8k
How to Talk to Developers About Accessibility
jct
2
560
Producing Creativity
orderedlist
PRO
348
41k
Evolving SEO for Evolving Search Engines
ryanjones
0
300
We Have a Design System, Now What?
morganepeng
55
8.3k
Embracing the Ebb and Flow
colly
88
5.2k
Building Applications with DynamoDB
mza
96
7.2k
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