Last active
August 29, 2015 14:22
-
-
Save hitsumabushi/f2731020896f311ecd3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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