Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

ansible

БесплатноБез исполняемых скриптовНе проверен

Ansible is an agentless automation tool that configures servers and deploys applications over SSH from YAML playbooks. Use when the user needs to write…

TerminalSkillsот TerminalSkills★ 221 звезда на GitHub15 установок в других каталогах

Об этом скилле

Ansible

Overview

Ansible connects to managed nodes over SSH (no agent) and runs tasks from YAML playbooks. Tasks are idempotent: a second run changes nothing if the host already matches. This skill covers installation, inventory, playbooks, roles, Vault, configuration and the everyday commands. Use fully qualified module names (ansible.builtin.apt, ansible.posix.synchronize, community.general.ufw) so playbooks keep working when collections are split or renamed.

Instructions

Install

pipx install ansible          # full package: ansible-core plus the community collections
# or: pip install ansible     # inside a virtualenv
ansible --version             # ansible-core 2.21 needs Python 3.12+ on the controller

Targets need Python (set ansible_python_interpreter if auto-discovery picks the wrong one). Ansible does not run its control node on Windows.

Inventory

# inventory/production.ini
[webservers]
web01.acme-shop.net ansible_host=10.0.1.10
web02.acme-shop.net ansible_host=10.0.1.11

[databases]
db01.acme-shop.net ansible_host=10.0.2.10

[production:children]
webservers
databases

[all:vars]
ansible_user=deploy
ansible_ssh_private_key_file=~/.ssh/deploy_ed25519

Variables for the production group live in inventory/group_vars/production/ (next to the inventory, so every playbook loads them). Check with ansible-inventory -i inventory/production.ini --list --yaml and ansible all -m ansible.builtin.ping.

Playbook

# playbooks/webserver.yml
---
- name: Configure web servers
  hosts: webservers
  become: true
  vars:
    nginx_port: 80
    app_root: /var/www/app

  tasks:
    - name: Install nginx
      ansible.builtin.apt:
        name: nginx
        state: present
        update_cache: true
        cache_valid_time: 3600

    - name: Deploy site configuration
      ansible.builtin.template:
        src: templates/nginx.conf.j2
        dest: /etc/nginx/sites-available/default
        owner: root
        group: root
        mode: "0644"
      notify: Reload nginx

    - name: Create the app directory
      ansible.builtin.file:
        path: "{{ app_root }}"
        state: directory
        owner: www-data
        group: www-data
        mode: "0755"

    - name: Copy application files
      ansible.posix.synchronize:
        src: files/app/
        dest: "{{ app_root }}/"
      notify: Reload nginx

    - name: Make sure nginx runs at boot
      ansible.builtin.service:
        name: nginx
        state: started
        enabled: true

  handlers:
    - name: Reload nginx
      ansible.builtin.service:
        name: nginx
        state: reloaded

Handlers run once at the end of the play, only if a notifying task changed something.

Rolling deployment with a health check before the next batch:

# playbooks/deploy-app.yml
---
- name: Deploy application
  hosts: webservers
  become: true
  serial: 2
  max_fail_percentage: 25

  pre_tasks:
    - name: Take the host out of the load balancer
      ansible.builtin.uri:
        url: "http://lb.acme-shop.net/api/deregister/{{ inventory_hostname }}"
        method: POST
        headers:
          Authorization: "Bearer {{ lb_api_token }}"
      delegate_to: localhost
      become: false

  roles:
    - role: app_deploy
      vars:
        app_version: "{{ deploy_version | default('latest') }}"

  post_tasks:
    - name: Wait for the health check
      ansible.builtin.uri:
        url: "http://{{ inventory_hostname }}:{{ app_port }}/health"
        status_code: 200
      register: health
      until: health.status == 200
      retries: 5
      delay: 10
      delegate_to: localhost
      become: false

    - name: Put the host back
      ansible.builtin.uri:
        url: "http://lb.acme-shop.net/api/register/{{ inventory_hostname }}"
        method: POST
        headers:
          Authorization: "Bearer {{ lb_api_token }}"
      delegate_to: localhost
      become: false

Roles

Layout: roles/common/{tasks,handlers,defaults,templates,files}/. Use underscores in role names.

# roles/common/tasks/main.yml
---
- name: Set the timezone
  community.general.timezone:
    name: "{{ server_timezone }}"

- name: Install baseline packages
  ansible.builtin.apt:
    name: [curl, vim, htop, unzip, jq, fail2ban]
    state: present

- name: Allow required ports
  community.general.ufw:
    rule: allow
    port: "{{ item }}"
    proto: tcp
  loop: "{{ allowed_ports }}"

- name: Enable the firewall (port 22 is allowed above)
  community.general.ufw:
    state: enabled
    policy: deny
# roles/common/defaults/main.yml
---
server_timezone: UTC
allowed_ports: ["22", "80", "443"]

Vault

ansible-vault create inventory/group_vars/production/vault.yml     # prompts for a password
ansible-vault edit inventory/group_vars/production/vault.yml
ansible-vault encrypt_string --vault-password-file ~/.vault_pass 'Zk3p9-rT7q' --name vault_db_password
ansible-playbook playbook
Полный SKILL.md на GitHub

Установить ansible в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

_scores.json

FAQ

Что делает скилл ansible?

Ansible is an agentless automation tool that configures servers and deploys applications over SSH from YAML playbooks. Use when the user needs to write playbooks, manage inventory, create roles, protect secrets with Ansible Vault, or run rolling multi-server deployments across environments.

Как установить скилл ansible?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл ansible запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить ansible с