
#!/usr/bin/python | |
import json | |
def main(): | |
module = AnsibleModule( | |
argument_spec=dict( | |
appkey=dict(required=True), | |
city=dict(default='munich,de'), | |
treshold=dict(required=True, type='float') | |
), | |
) | |
city = module.params['city'] | |
treshold = module.params['treshold'] | |
appkey = module.params['appkey'] | |
url = 'http://api.openweathermap.org/data/2.5/weather?q={}&APPID={}&units=metric'.format(city, appkey) | |
curl_result = module.run_command(['/usr/bin/curl', 'GET', url]) | |
if curl_result[0] != 0: | |
module.fail_json(msg='Curl command returned non-0 exit {}, the output was {}'.format(curl_result[0], | |
curl_result[1])) | |
else: | |
curl_result_dict = json.loads(curl_result[1]) | |
http_resp_code = curl_result_dict['cod'] | |
if http_resp_code not in [200]: | |
module.fail_json(msg='non-200 response code {} received, the output was {}'.format(http_resp_code, | |
curl_result[1])) | |
else: | |
temperature = curl_result_dict['main']['temp'] | |
if temperature > treshold: | |
module.exit_json(changed=True, decision='Run, Yves, Run, it is {} in {}'.format(temperature, city)) | |
if temperature < treshold: | |
module.exit_json(changed=False, decision='Stop, Yves, Stop, it is {} in {}'.format(temperature, city)) | |
from ansible.module_utils.basic import * | |
main() |

















I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND