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
RHTN2021.1.14 AnsibleTwitterModuleの話
Search
nanodayo
January 14, 2021
Programming
340
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
RHTN2021.1.14 AnsibleTwitterModuleの話
RHTN2021.1.14 で話したもの
nanodayo
January 14, 2021
More Decks by nanodayo
See All by nanodayo
RHTN2021.1.14 お料理ハンズオン
nanodayo
0
1.3k
Other Decks in Programming
See All in Programming
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4.8k
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
310
FreeBSDでZabbixを動かす
kenkino
0
310
SONY CISC-NEWS NWS-1750 + NWB-225 フレームバッファの NetBSD/news68k ドライバ実装 / OSC2026Hiroshima
tsutsui
0
120
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
330
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
520
UPDATE をやめる — EF Core でマスタをバージョン管理する
panda728
PRO
0
250
The Rails Doctrine Decade
koic
2
170
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
160
更なる可用性を求めて、5年間運用したKotlinのアプリケーションをGoでリプレイスする話
ken_tunc
0
300
AHC070解法紹介
eijirou
0
130
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
4
2.9k
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
37
7.4k
The #1 spot is gone: here's how to win anyway
tamaranovitovic
4
1.2k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.6k
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
440
Conquering PDFs: document understanding beyond plain text
inesmontani
PRO
4
3.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
SEO in 2025: How to Prepare for the Future of Search
ipullrank
3
3.8k
Product Roadmaps are Hard
iamctodd
55
13k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
510
Transcript
まずは一句 我々も バグか仕様か わからない 詳しくは オープンソース製品の「仕様」 - 赤帽エンジニアブログ にて
Ansible Twitter module の話 Red Hat コンサルタント 松井大輔
Ansible Twitter module とは • Twitterにつぶやきを投稿する。 それだけの機能の Ansible moduleです •
以下で公開中 Ansible Galaxy https://galaxy.ansible.com/nanodayo/twitter GitHub https://github.com/nanodayo/ansible_twitter_module
何故 Ansible twitter module を作ったか 実用性は全く考えてない。ジョークアプリの感覚で作った。 • Ansible Moduleを作ってみたかった •
twitter のAPIも使ってみたかった
Ansible twitter module 開発の道のり
Step1: Ansible module の作り方を調べる • 公式 ◦ Ansible module development:
getting started ◦ https://docs.ansible.com/ansible/latest/dev_guide/developing_modules_general.html • 赤帽エンジニアブログ by ひよこ大佐 ◦ Ansibleのモジュールを開発してみよう ◦ https://rheb.hatenablog.com/entry/develop_ansible_module
Step2: TwitterにAPI Clientを登録 • https://developer.twitter.com/ で アプリの用途等を入力 • ansible_twitter_module で登録
• 自分のアカウントで ansible_twitter_module を 使うためのAPI Keyを発行
Step3: moduleを作る • Python で実装 • Pythonの twitter library https://pypi.org/project/twitter/
• twitter library に必要な値を module のパラメータとして定義 ◦ Twitter のAPI Key ◦ つぶやき内容 module = AnsibleModule( argument_spec={ 'state': {'required': False, 'default': 'present'}, 'server': {'required': False, 'default': 'api.twitter.com'}, 'https': {'required': False, 'type': 'bool', 'default': True}, 'consumer_key': {'required': True}, 'consumer_secret_key': {'required': True}, 'access_token': {'required': True}, 'access_token_secret': {'required': True}, 'tweet': {'required': True} }, ) tweet_text = module.params.get('tweet') tweet_result = Twitter( auth=OAuth( module.params.get('access_token'), module.params.get('access_token_secret'), module.params.get('consumer_key'), module.params.get('consumer_secret_key') ), domain=module.params.get('server'), secure=module.params.get('https') ) try: tweet_result.statuses.update(status=tweet_text)
Step4: つぶやく
Step5: Ansible Galaxy へ登録
Step6: CI対応 • GitHun Action + Toxで実行 • LINT ◦
Pylint, flake8 • Unit test, sanity test ◦ 未着
Step7: 機能拡張 • 公式以外のtwitter サーバを使う ◦ テスト用途 ◦ サーバを指定するための Module
引数を追加 • 既に同じツイートがあった場合は changed にしないで正常終了 ◦ Twitter 側で重複ツイートはNGにしている ◦ Twitter のResponse Codeから判定可 Response Codes | Docs ▪ 同じコード(403, 187)を返す ダミーサーバを作成してテスト @app.route('/1.1/statuses/update.json', methods=['POST']) def post_tweet(): tweet = request.form['status'] if tweet not in tweets: tweets.append(request.form['status']) return "", 200 else: return jsonify({ "errors": [ { "code": 187, "message": "Status is a duplicate." } ] }), 403
実行例 (中略) "item": { "debug_info": { "errors": [ { "code":
187, "message": "Status is a duplicate." } ] }, "tweet": "Ansible moduleからのつぶやきテスト https://galaxy.ansible.com/nanodayo/twitter" } } PLAY RECAP ******************************************************************* *************************************** localhost : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 (中略) "https": true, "server": "api.twitter.com", "state": "present", "tweet": "Ansible moduleからのつぶやきテスト https://galaxy.ansible.com/nanodayo/twitter" } }, "item": { "tweet": "Ansible moduleからのつぶやきテスト https://galaxy.ansible.com/nanodayo/twitter" } } PLAY RECAP ******************************************************************* ******************************************************** localhost : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 重複ツイートがない場合 重複ツイートがある場合
今後の開発計画 • CIのテスト拡充 ◦ Sanity Test ◦ Unit Test •
twitter APIのダミーサーバでのテストをCIに組み込み ◦ CIの中で重複ツイートのテストを実施