From the course: Ansible for Automation Essential Training: Advanced Playbooks, Roles, and Diverse Hosts

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

Using Ansible with APIs

Using Ansible with APIs

- [Instructor] Something I do somewhat frequently is interact with various APIs. It's nice when there is a purpose-built module to work with an API, but even if there isn't, you can always use the URI module, which is exactly what I plan to demonstrate. There are a lot of APIs out there that I can hit publicly to do some demonstrations, but I figure I'd use the US government's weather interface at api.weather.gov. It's convenient because it doesn't require any authentication. I can just hit it with no account and it will respond. Looking at my playbook, I first wanted to point out that I'm operating against the local host. This is because I'm going to just be executing everything from the server running Ansible. I'm not connecting to some remote host via SSH, whether I'm just issuing essential web calls. Taking a look at the first task, I'm using the URI module, and the most important part is the URL parameter. Believe it or not, I can just take this and throw it at a web browser for…

Contents