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
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
Spec Driven Development | AI Summit Lisbon
danielsogl
PRO
0
190
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
2
680
Agentic UI
manfredsteyer
PRO
0
160
ユニットテストの先へ:テスト技法で要求・仕様を整理するJava開発実践 / Beyond_Unit_Testing_Practical_Java_Development_Techniques_for_Organizing_Requirements_and_Specifications
shimashima35
0
400
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
540
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
1
240
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
130
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
120
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6k
Snowflake Summitでの新機能 CoCo / CoWork / snowflake-summit-2026-overall-what-new-coco
tatsuhiro
1
140
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.7k
A2UI という光を覗いてみる
satohjohn
1
140
Featured
See All Featured
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Designing for humans not robots
tammielis
254
26k
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
330
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
What's in a price? How to price your products and services
michaelherold
247
13k
From π to Pie charts
rasagy
0
210
The Curse of the Amulet
leimatthew05
1
13k
Done Done
chrislema
186
16k
Raft: Consensus for Rubyists
vanstee
141
7.5k
First, design no harm
axbom
PRO
2
1.2k
For a Future-Friendly Web
brad_frost
183
10k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
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の中で重複ツイートのテストを実施