Skip to content

Instantly share code, notes, and snippets.

@hitsumabushi
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitsumabushi/f2731020896f311ecd3b to your computer and use it in GitHub Desktop.
Save hitsumabushi/f2731020896f311ecd3b to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# -*- coding: utf-8 -*-.
import exceptions
import requests
import tempfile
from bs4 import BeautifulSoup
def main():
module = AnsibleModule(
# 引数の処理
argument_spec = dict(
outfile = dict(requiered = False, default = None, type = 'str'),
),
# -C: check modeのサポート
supports_check_mode = True
)
# 処理を書く
## エラーは気にしない...
AA_URL = "http://www.asciiartfarts.com/random.cgi"
r = requests.get(AA_URL)
soup = BeautifulSoup(r.text)
str = soup.find_all("pre")[1].string
# check mode になっているかチェック
if module.check_mode:
pass
else:
out = module.params["outfile"] if module.params["outfile"] == "" else "/tmp/hoge"
with open(module.params["outfile"], 'w') as f:
f.write(str)
# 結果の返却
result = dict(msg = str, changed = True)
module.exit_json(**result)
# おまじないと思う
from ansible.module_utils.basic import *
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment