🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours scrolling social media and waste money on things we forget, but won’t spend 30 minutes a day earning certifications that can change our lives.
Master in DevOps, SRE, DevSecOps & MLOps by DevOpsSchool!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

Ansible Module Sample Code to Work with API – Example 1

```yaml
---
- name: This sets up an httpd webserver
hosts: localhost
tasks:
- debug:
msg: My Name is Rajesh
- weather:
appkey: fe8f2030bd325e2f9c85a96ab20aaa9f
treshold: 2
register: output
- debug:
var: output.decision
```
view raw site.yaml hosted with ❤ by GitHub
#!/usr/bin/python
import requests
import json
def get_temperature(appkey, city, module, units='metric'):
session = requests.Session()
headers = {'Content-Type': 'application/json'}
url = 'http://api.openweathermap.org/data/2.5/weather'
params = {'q': city, 'APPID': appkey, 'units': units}
try:
response = session.request('GET', url, headers=headers, params=params)
except requests.exceptions.RequestException as e:
module.fail_json(msg=e)
if response.status_code not in [200]:
module.fail_json(msg=(response.status_code, response.content))
response_content = json.loads(response.content)
return response_content['main']['temp']
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']
temperature = get_temperature(appkey, city, module)
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()

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.