DEV Community

Alex Spinov
Alex Spinov

Posted on

Ansible Has a Free API: Automate Everything Without Agents

Why Ansible

Ansible automates server configuration, application deployment, and orchestration — all agentless, over SSH. Write playbooks in YAML, run them against any server.

Install

pip install ansible
Enter fullscreen mode Exit fullscreen mode

Inventory

# inventory.ini
[web]
web1.example.com
web2.example.com

[db]
db1.example.com

[all:vars]
ansible_user=deploy
ansible_python_interpreter=/usr/bin/python3
Enter fullscreen mode Exit fullscreen mode

First Playbook

# deploy.yaml
- hosts: web
  become: true
  tasks:
    - name: Install Nginx
      apt:
        name: nginx
        state: present
        update_cache: true

    - name: Copy config
      template:
        src: nginx.conf.j2
        dest: /etc/nginx/nginx.conf
      notify: Restart Nginx

    - name: Ensure Nginx is running
      service:
        name: nginx
        state: started
        enabled: true

  handlers:
    - name: Restart Nginx
      service:
        name: nginx
        state: restarted
Enter fullscreen mode Exit fullscreen mode
ansible-playbook -i inventory.ini deploy.yaml
Enter fullscreen mode Exit fullscreen mode

Roles (Reusable Components)

ansible-galaxy init roles/webserver
Enter fullscreen mode Exit fullscreen mode
# roles/webserver/tasks/main.yaml
- name: Install packages
  apt:
    name: "{{ item }}"
    state: present
  loop:
    - nginx
    - certbot

- name: Deploy site
  copy:
    src: index.html
    dest: /var/www/html/
Enter fullscreen mode Exit fullscreen mode

Ansible Vault (Secrets)

# Encrypt secrets
ansible-vault create secrets.yaml

# Use encrypted vars in playbook
ansible-playbook deploy.yaml --ask-vault-pass
Enter fullscreen mode Exit fullscreen mode

Key Features

  • Agentless — SSH only, no agents to install
  • YAML playbooks — readable, version-controllable
  • Idempotent — run multiple times safely
  • 3,000+ modules — cloud, network, containers, everything
  • Roles — reusable, shareable from Ansible Galaxy
  • Vault — encrypted secrets management

Resources


Need to extract server configs, infrastructure data, or automation metrics? Check out my Apify tools or email spinov001@gmail.com for custom solutions.

Top comments (0)