Agent Skills by ALSEL
Anthropic Claude個人生産性⭐ リポ 0品質スコア 50/100

ansible-expert

構成管理・自動化・Infrastructure as CodeのためのAnsibleを専門家レベルでサポートします。Playbook作成からロール設計、インベントリ管理まで、Ansibleに関するあらゆる課題に対応します。

description の原文を見る

Expert-level Ansible for configuration management, automation, and infrastructure as code

SKILL.md 本文

Ansible エキスパート

Ansible に関するエキスパートガイダンス - 宣言型 YAML プレイブックを使用した設定管理、アプリケーションデプロイメント、IT オートメーション。

コア概念

Ansible アーキテクチャ

  • コントロールノード (Ansible を実行)
  • マネージドノード (ターゲットシステム)
  • インベントリ (ホストとグループ)
  • プレイブック (YAML オートメーションスクリプト)
  • モジュール (作業単位)
  • ロール (再利用可能なオートメーション単位)
  • プラグイン (機能を拡張)

主な機能

  • エージェントレス (SSH ベース)
  • べき等な操作
  • 宣言型構文
  • 人間が読みやすい YAML
  • モジュールで拡張可能
  • プッシュベースの設定
  • 並列実行

ユースケース

  • 設定管理
  • アプリケーションデプロイメント
  • プロビジョニング
  • 継続的デリバリー
  • セキュリティオートメーション
  • オーケストレーション

インストール

# pip を使用
pip install ansible

# apt を使用 (Ubuntu/Debian)
sudo apt update
sudo apt install ansible

# yum を使用 (RHEL/CentOS)
sudo yum install ansible

# インストール確認
ansible --version

インベントリ

基本的なインベントリ (INI 形式)

# inventory/hosts
[webservers]
web1.example.com
web2.example.com ansible_host=192.168.1.10

[databases]
db1.example.com ansible_user=dbadmin
db2.example.com

[production:children]
webservers
databases

[production:vars]
ansible_python_interpreter=/usr/bin/python3
ansible_connection=ssh

YAML インベントリ

# inventory/hosts.yml
all:
  children:
    webservers:
      hosts:
        web1.example.com:
        web2.example.com:
          ansible_host: 192.168.1.10
    databases:
      hosts:
        db1.example.com:
          ansible_user: dbadmin
        db2.example.com:
    production:
      children:
        webservers:
        databases:
      vars:
        ansible_python_interpreter: /usr/bin/python3
        ansible_connection: ssh

動的インベントリ

#!/usr/bin/env python3
# inventory/aws_ec2.py
import json
import boto3

def get_inventory():
    ec2 = boto3.client('ec2', region_name='us-east-1')
    response = ec2.describe_instances(Filters=[
        {'Name': 'instance-state-name', 'Values': ['running']}
    ])

    inventory = {
        '_meta': {'hostvars': {}},
        'all': {'hosts': []},
        'webservers': {'hosts': []},
        'databases': {'hosts': []},
    }

    for reservation in response['Reservations']:
        for instance in reservation['Instances']:
            ip = instance['PrivateIpAddress']
            tags = {tag['Key']: tag['Value'] for tag in instance.get('Tags', [])}

            inventory['all']['hosts'].append(ip)
            inventory['_meta']['hostvars'][ip] = {
                'ansible_host': ip,
                'instance_id': instance['InstanceId'],
                'instance_type': instance['InstanceType'],
            }

            # Group by role tag
            role = tags.get('Role', '')
            if role in inventory:
                inventory[role]['hosts'].append(ip)

    return inventory

if __name__ == '__main__':
    print(json.dumps(get_inventory(), indent=2))

プレイブック

基本的なプレイブック

# playbooks/webserver.yml
---
- name: Configure web servers
  hosts: webservers
  become: yes
  vars:
    app_port: 8080
    app_user: webapp

  tasks:
    - name: Install nginx
      apt:
        name: nginx
        state: present
        update_cache: yes

    - name: Start and enable nginx
      systemd:
        name: nginx
        state: started
        enabled: yes

    - name: Copy nginx configuration
      template:
        src: templates/nginx.conf.j2
        dest: /etc/nginx/sites-available/default
        mode: '0644'
      notify: Reload nginx

    - name: Create application user
      user:
        name: "{{ app_user }}"
        state: present
        shell: /bin/bash

  handlers:
    - name: Reload nginx
      systemd:
        name: nginx
        state: reloaded

高度なプレイブック

# playbooks/deploy-app.yml
---
- name: Deploy application
  hosts: webservers
  become: yes
  vars:
    app_name: myapp
    app_version: "{{ version | default('latest') }}"
    app_port: 8080
    deploy_user: deployer

  pre_tasks:
    - name: Check if required variables are defined
      assert:
        that:
          - app_name is defined
          - app_version is defined
        fail_msg: "Required variables are not defined"

  tasks:
    - name: Create deployment directory
      file:
        path: "/opt/{{ app_name }}"
        state: directory
        owner: "{{ deploy_user }}"
        group: "{{ deploy_user }}"
        mode: '0755'

    - name: Download application artifact
      get_url:
        url: "https://artifacts.example.com/{{ app_name }}/{{ app_version }}/{{ app_name }}.jar"
        dest: "/opt/{{ app_name }}/{{ app_name }}-{{ app_version }}.jar"
        mode: '0644'
      register: download_result

    - name: Create systemd service
      template:
        src: templates/app.service.j2
        dest: "/etc/systemd/system/{{ app_name }}.service"
        mode: '0644'
      notify:
        - Reload systemd
        - Restart application

    - name: Enable application service
      systemd:
        name: "{{ app_name }}"
        enabled: yes

    - name: Wait for application to start
      wait_for:
        port: "{{ app_port }}"
        delay: 5
        timeout: 60
      when: download_result.changed

    - name: Check application health
      uri:
        url: "http://localhost:{{ app_port }}/health"
        status_code: 200
      retries: 3
      delay: 5

  post_tasks:
    - name: Clean up old versions
      shell: |
        cd /opt/{{ app_name }}
        ls -t {{ app_name }}-*.jar | tail -n +4 | xargs -r rm
      args:
        executable: /bin/bash

  handlers:
    - name: Reload systemd
      systemd:
        daemon_reload: yes

    - name: Restart application
      systemd:
        name: "{{ app_name }}"
        state: restarted

条件分岐とループ

---
- name: Conditional and loop examples
  hosts: all
  tasks:
    - name: Install package (Debian)
      apt:
        name: "{{ item }}"
        state: present
      loop:
        - nginx
        - postgresql
        - redis
      when: ansible_os_family == "Debian"

    - name: Install package (RedHat)
      yum:
        name: "{{ item }}"
        state: present
      loop:
        - nginx
        - postgresql
        - redis
      when: ansible_os_family == "RedHat"

    - name: Create users
      user:
        name: "{{ item.name }}"
        state: present
        groups: "{{ item.groups }}"
      loop:
        - { name: 'alice', groups: 'wheel' }
        - { name: 'bob', groups: 'users' }
        - { name: 'charlie', groups: 'developers' }

    - name: Configure services
      systemd:
        name: "{{ item.name }}"
        state: "{{ item.state }}"
        enabled: "{{ item.enabled }}"
      loop:
        - { name: 'nginx', state: 'started', enabled: yes }
        - { name: 'postgresql', state: 'started', enabled: yes }
        - { name: 'redis', state: 'started', enabled: yes }

    - name: Set fact based on condition
      set_fact:
        environment_type: "{{ 'production' if inventory_hostname in groups['production'] else 'development' }}"

    - name: Debug conditional
      debug:
        msg: "This is a {{ environment_type }} server"

ロール

ロール構造

roles/
└── webserver/
    ├── defaults/
    │   └── main.yml         # デフォルト変数
    ├── files/
    │   └── app.conf         # 静的ファイル
    ├── handlers/
    │   └── main.yml         # ハンドラ
    ├── meta/
    │   └── main.yml         # ロールメタデータと依存関係
    ├── tasks/
    │   └── main.yml         # メインタスクリスト
    ├── templates/
    │   └── nginx.conf.j2    # Jinja2 テンプレート
    ├── tests/
    │   └── test.yml         # ロールテスト
    └── vars/
        └── main.yml         # ロール変数

ロール例

# roles/webserver/defaults/main.yml
---
nginx_port: 80
nginx_user: www-data
document_root: /var/www/html

# roles/webserver/tasks/main.yml
---
- name: Install nginx
  apt:
    name: nginx
    state: present
    update_cache: yes

- name: Copy nginx configuration
  template:
    src: nginx.conf.j2
    dest: /etc/nginx/nginx.conf
    mode: '0644'
  notify: Restart nginx

- name: Create document root
  file:
    path: "{{ document_root }}"
    state: directory
    owner: "{{ nginx_user }}"
    mode: '0755'

- name: Start nginx
  systemd:
    name: nginx
    state: started
    enabled: yes

# roles/webserver/handlers/main.yml
---
- name: Restart nginx
  systemd:
    name: nginx
    state: restarted

# roles/webserver/templates/nginx.conf.j2
user {{ nginx_user }};
worker_processes auto;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    server {
        listen {{ nginx_port }};
        server_name {{ ansible_hostname }};

        root {{ document_root }};
        index index.html;

        location / {
            try_files $uri $uri/ =404;
        }
    }
}

# プレイブック内でロールを使用
---
- name: Configure web servers
  hosts: webservers
  become: yes
  roles:
    - role: webserver
      vars:
        nginx_port: 8080
        document_root: /var/www/myapp

ロール依存関係

# roles/app/meta/main.yml
---
dependencies:
  - role: common
  - role: nginx
    vars:
      nginx_port: 8080
  - role: postgresql
    when: database_enabled | default(false)

テンプレート (Jinja2)

{# templates/app.conf.j2 #}
# Application configuration for {{ app_name }}
# Generated by Ansible on {{ ansible_date_time.iso8601 }}

[server]
host = {{ ansible_default_ipv4.address }}
port = {{ app_port }}
workers = {{ ansible_processor_vcpus }}

[database]
host = {{ db_host }}
port = {{ db_port }}
name = {{ db_name }}
user = {{ db_user }}
password = {{ db_password }}

[cache]
enabled = {{ cache_enabled | default(true) | lower }}
{% if cache_enabled | default(true) %}
backend = redis
redis_host = {{ redis_host }}
redis_port = {{ redis_port }}
{% endif %}

[features]
{% for feature, enabled in features.items() %}
{{ feature }} = {{ enabled | lower }}
{% endfor %}

{% if environment == 'production' %}
[production]
debug = false
log_level = warning
{% else %}
[development]
debug = true
log_level = debug
{% endif %}

変数とファクト

変数の優先順位 (低から高)

  1. ロールのデフォルト
  2. インベントリファイル/スクリプトのグループ変数
  3. インベントリ group_vars/all
  4. プレイブック group_vars/all
  5. インベントリ group_vars/*
  6. プレイブック group_vars/*
  7. インベントリファイル/スクリプトのホスト変数
  8. インベントリ host_vars/*
  9. プレイブック host_vars/*
  10. ホストファクト
  11. プレイ変数
  12. プレイ vars_prompt
  13. プレイ vars_files
  14. ロール変数
  15. ブロック変数
  16. タスク変数
  17. エクストラ変数 (-e フラグ)

変数の使用

---
- name: Variable examples
  hosts: all
  vars:
    app_name: myapp
    app_version: 1.0.0
  vars_files:
    - vars/common.yml
    - "vars/{{ environment }}.yml"

  tasks:
    - name: Load variables from file
      include_vars:
        file: "vars/{{ ansible_distribution }}.yml"

    - name: Set fact
      set_fact:
        full_app_name: "{{ app_name }}-{{ app_version }}"

    - name: Register output
      command: hostname
      register: hostname_output

    - name: Use registered variable
      debug:
        msg: "Hostname is {{ hostname_output.stdout }}"

    - name: Access facts
      debug:
        msg: |
          OS: {{ ansible_distribution }} {{ ansible_distribution_version }}
          Kernel: {{ ansible_kernel }}
          CPU: {{ ansible_processor_vcpus }} cores
          Memory: {{ ansible_memtotal_mb }} MB
          IP: {{ ansible_default_ipv4.address }}

エラーハンドリング

---
- name: Error handling examples
  hosts: all
  tasks:
    - name: Task that might fail
      command: /bin/false
      ignore_errors: yes

    - name: Task with custom error handling
      block:
        - name: Try to start service
          systemd:
            name: myapp
            state: started
      rescue:
        - name: Log error
          debug:
            msg: "Failed to start myapp"

        - name: Try alternative
          systemd:
            name: myapp-fallback
            state: started
      always:
        - name: This always runs
          debug:
            msg: "Cleanup task"

    - name: Assert condition
      assert:
        that:
          - ansible_memtotal_mb >= 2048
          - ansible_processor_vcpus >= 2
        fail_msg: "Server does not meet minimum requirements"

    - name: Fail when condition
      fail:
        msg: "Production deployment requires version tag"
      when:
        - environment == 'production'
        - app_version == 'latest'

    - name: Changed when condition
      command: /usr/local/bin/check_status.sh
      register: result
      changed_when: "'updated' in result.stdout"
      failed_when: result.rc not in [0, 2]

Ansible Vault

# 暗号化されたファイルを作成
ansible-vault create secrets.yml

# 暗号化されたファイルを編集
ansible-vault edit secrets.yml

# 既存ファイルを暗号化
ansible-vault encrypt vars/production.yml

# ファイルを復号化
ansible-vault decrypt vars/production.yml

# 暗号化されたファイルを表示
ansible-vault view secrets.yml

# キーを変更 (パスワード変更)
ansible-vault rekey secrets.yml
# secrets.yml (暗号化)
---
db_password: supersecret
api_key: abc123xyz
ssl_key: |
  -----BEGIN PRIVATE KEY-----
  ...
  -----END PRIVATE KEY-----

# プレイブックで使用
---
- name: Deploy with secrets
  hosts: production
  vars_files:
    - secrets.yml
  tasks:
    - name: Configure database
      template:
        src: db.conf.j2
        dest: /etc/db.conf
      no_log: yes  # 機密データをログに出力しない
# Vault パスワードを指定してプレイブックを実行
ansible-playbook playbook.yml --ask-vault-pass

# パスワードファイルを使用
ansible-playbook playbook.yml --vault-password-file ~/.vault_pass

# 複数の Vault ID を使用
ansible-playbook playbook.yml --vault-id prod@prompt --vault-id dev@~/.vault_dev

ベストプラクティス

プレイブック構成

ansible-project/
├── ansible.cfg
├── inventory/
│   ├── production/
│   │   ├── hosts.yml
│   │   └── group_vars/
│   └── staging/
│       ├── hosts.yml
│       └── group_vars/
├── playbooks/
│   ├── site.yml
│   ├── webservers.yml
│   └── databases.yml
├── roles/
│   ├── common/
│   ├── nginx/
│   └── postgresql/
├── group_vars/
│   ├── all.yml
│   └── webservers.yml
├── host_vars/
└── files/

べき等性

# ❌ べき等でない
- name: Add line to file
  shell: echo "server {{ ansible_hostname }}" >> /etc/hosts

# ✅ べき等
- name: Add line to file
  lineinfile:
    path: /etc/hosts
    line: "server {{ ansible_hostname }}"
    state: present

パフォーマンス

  • strategy: free を使用して高速実行
  • ansible.cfg でパイプライニングを有効化
  • 長時間実行タスクに async を使用
  • ファクト収集が不要な場合は無効化
  • ローリングアップデートに serial を使用
# ansible.cfg
[defaults]
forks = 20
host_key_checking = False
pipelining = True
gathering = smart
fact_caching = jsonfile
fact_caching_connection = /tmp/ansible_facts
fact_caching_timeout = 86400

# パフォーマンス最適化を含むプレイブック
---
- name: Fast deployment
  hosts: webservers
  strategy: free
  gather_facts: no
  serial: 5  # 一度に 5 つのホストにデプロイ

  tasks:
    - name: Long running task
      command: /usr/local/bin/build.sh
      async: 3600
      poll: 0
      register: build_job

    - name: Check build status
      async_status:
        jid: "{{ build_job.ansible_job_id }}"
      register: job_result
      until: job_result.finished
      retries: 60
      delay: 30

セキュリティ

  • シークレットに Ansible Vault を使用
  • 機密タスクに no_log: yes を使用
  • 適切なファイルパーミッションを設定
  • become を最小限に使用
  • SSL 証明書を検証
  • パスワードではなく SSH キーを使用

テスト

Molecule (ロールテスト)

# Molecule をインストール
pip install molecule molecule-docker

# Molecule を初期化
cd roles/myapp
molecule init scenario

# テストを実行
molecule test

# テストワークフロー
molecule create    # テストインスタンスを作成
molecule converge  # プレイブックを実行
molecule verify    # テストを実行
molecule destroy   # クリーンアップ
# molecule/default/molecule.yml
---
dependency:
  name: galaxy
driver:
  name: docker
platforms:
  - name: ubuntu
    image: geerlingguy/docker-ubuntu2004-ansible
    pre_build_image: yes
provisioner:
  name: ansible
verifier:
  name: ansible

避けるべきアンチパターン

ロールを使用しない: 再利用可能なロール内にコードを整理する ❌ シェルコマンドばかり: 利用可能な場合はモジュールを使用 ❌ ハードコードされた値: 変数を使用 ❌ エラーハンドリングがない: block、rescue、always を使用 ❌ 平文でシークレットを保存: Ansible Vault を使用 ❌ テストがない: ロールテストに Molecule を使用 ❌ べき等性を無視: タスクは何度実行しても安全であるべき ❌ 複雑なプレイブック: より小さく、焦点を絞ったプレイブックに分割

リソース

ライセンス: Apache-2.0(寛容ライセンスのため全文を引用しています) · 原本リポジトリ

詳細情報

作者
personamanagmentlayer
リポジトリ
personamanagmentlayer/pcl
ライセンス
Apache-2.0
最終更新
不明

Source: https://github.com/personamanagmentlayer/pcl / ライセンス: Apache-2.0

関連スキル

汎用個人生産性⭐ リポ 7,456

newsblur-cli

ターミナルからNewsBlurを管理できます。フィードの閲覧、ストーリーの検索、記事の保存・共有、インテリジェンス分類器の学習、新しいフィードの発見、ワークフローの自動化がNewsBlur CLIで実現します。ユーザーがNewsBlurアカウントを操作したい場合、フィードの確認、購読管理、またはニュース読み込みに関するスクリプト構築時に活用してください。

by samuelclay
汎用個人生産性⭐ リポ 58,643

caveman-compress

自然言語のメモリファイル(CLAUDE.md、todos、preferences)を「原始人形式」に圧縮し、入力トークンを削減します。技術的な内容、コード、URL、構造はすべて保持したまま圧縮します。圧縮版が元のファイルを上書きし、人間が読める形のバックアップはFILE.original.mdとして保存されます。トリガー:/caveman-compress FILEPATH または「compress memory file」

by JuliusBrussee
ALSEL独自Anthropic Claude個人生産性

find-skills

日本語の意図から Agent Skills を発見する。「楽天SEOのスキル探して」「PDFを処理したい」「データ分析を自動化したい」などの日本語リクエストに対応。Claude Code (CLI)、Codex、Gemini CLI、claude.ai (Web) いずれでも動作。日本最大の Agent Skills データベース「Agent Skills by ALSEL」(11,000件超、全件日本語化、ダウンロード可能スキル8,600件超) から、ユーザーの意図に合うスキルを推薦・インストール案内する。

by 株式会社ALSEL
汎用個人生産性⭐ リポ 39,967

planning-and-task-breakdown

仕事を順序立てたタスクに分割します。仕様書や要件が明確にあり、実装可能なタスクに分解する必要がある場合に利用してください。タスクが大きすぎて着手しづらい場合、スコープを見積もる必要がある場合、または並列で作業を進められる場合に活用できます。

by addyosmani
Anthropic Claude個人生産性⭐ リポ 132,723

docx

このスキルは、ユーザーがWord文書(.docxファイル)を作成、読み込み、編集、操作したいときに使用します。以下の場合に実行してください:「Word文書」「.docx」などの記述、または目次・見出し・ページ番号・レターヘッドなどのフォーマットを含む専門的な文書の作成リクエスト。また、.docxファイルのコンテンツ抽出・再編成、文書への画像挿入・置換、Word形式での検索置換、変更履歴やコメント機能の使用、コンテンツを整形したWord文書への変換の場合も対象です。ユーザーが「レポート」「メモ」「手紙」「テンプレート」などの成果物をWord形式または.docxファイルで求める場合はこのスキルを使用してください。PDF、スプレッドシート、Google Docs、文書作成と無関係なコーディングタスクには使用しないでください。

by anthropics
汎用個人生産性⭐ リポ 39,967

idea-refine

アイデアを反復的に改善します。構造化された発散的思考と収束的思考を通じて、アイデアを洗練させることができます。「idea-refine」または「ideate」を使用してトリガーします。

by addyosmani
本サイトは GitHub 上で公開されているオープンソースの SKILL.md ファイルをクロール・インデックス化したものです。 各スキルの著作権は原作者に帰属します。掲載に問題がある場合は info@alsel.co.jp または /takedown フォームよりご連絡ください。
原作者: personamanagmentlayer · personamanagmentlayer/pcl · ライセンス: Apache-2.0