agentleFS
realsigridjinrealsigridjin/hello-ansible-skills/skills/ansible-convert/SKILL.md

ansible-convert

Skill89 starsChanged 10 months agoMITView on GitHub

Use when converting shell scripts to Ansible playbooks. Use when migrating bash automation, manual procedures, or Dockerfiles to idempotent Ansible tasks.

  • Deletes or force-pushes
  • Installs packages

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 3 are distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use command or shell only when no module exists.

    line 98
  2. Very specific:

    Place in defaults/main.yml for easy override.

    line 118
  3. Distinctive:

    Read entire script, identify major phases

    line 122
  4. Distinctive:

    Add handlers for service restarts

    line 126
  5. Distinctive:

    Verify idempotency: second run shows no changes

    line 128

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Shell to Ansible Conversion

Overview

Shell scripts execute commands imperatively; Ansible declares desired state. Conversion means rethinking operations as state declarations, not translating commands line-by-line. The goal is idempotency: running twice produces identical results.

When to Use

  • Converting existing shell scripts to playbooks
  • Migrating manual server setup procedures
  • Replacing bash automation with Ansible
  • Converting Dockerfile RUN commands

Core Principle

Don't wrap shell commands in Ansible's shell module. Find the module that achieves the same end state declaratively.

# Shell: imperative
mkdir -p /opt/app
chown app:app /opt/app
# Ansible: declarative
- ansible.builtin.file:
    path: /opt/app
    state: directory
    owner: app
    group: app
    mode: '0755'

Conversion Table

Shell CommandAnsible ModuleNotes
mkdir -pansible.builtin.filestate: directory
cpansible.builtin.copyStatic files
cp with variablesansible.builtin.templateUse .j2 templates
rm -rfansible.builtin.filestate: absent
ln -sansible.builtin.filestate: link
chmod, chownInclude in file/copy/templatemode, owner, group params
apt-get installansible.builtin.aptupdate_cache: yes
yum installansible.builtin.yumOr use package for cross-platform
pip installansible.builtin.pipSpecify executable if needed
useraddansible.builtin.userHandles home, shell, groups
systemctl startansible.builtin.servicestate: started
systemctl enableansible.builtin.serviceenabled: yes
curl -Oansible.builtin.get_urlUse checksum for verification
tar -xzfansible.builtin.unarchiveremote_src: yes if already on target
echo >> fileansible.builtin.lineinfileEnsures line exists
cat > fileansible.builtin.copycontent: parameter

Control Flow Conversion

Conditionals

# Shell
if [ -f /etc/debian_version ]; then
    apt-get install nginx
fi
# Ansible
- ansible.builtin.apt:
    name: nginx
  when: ansible_os_family == "Debian"

Loops

# Shell
for user in alice bob; do
    useradd $user
done
# Ansible
- ansible.builtin.user:
    name: "{{ item }}"
  loop:
    - alice
    - bob

When Shell Module is Necessary

Use command or shell only when no module exists. Always add proper change detection:

- name: Run custom installer
  ansible.builtin.shell: /opt/app/install.sh
  args:
    creates: /opt/app/.installed  # Skip if file exists
  register: install_result
  changed_when: "'Installed' in install_result.stdout"
  failed_when: install_result.rc != 0 and 'already installed' not in install_result.stderr

Variable Extraction

Identify values to parameterize:

  • Version numbers → app_version: "1.2.3"
  • Paths → app_dir: "/opt/app"
  • Usernames → app_user: "appuser"
  • Ports → app_port: 8080

Place in defaults/main.yml for easy override.

Conversion Workflow

  1. Read entire script, identify major phases
  2. Map each command to Ansible module
  3. Extract hardcoded values as variables
  4. Order tasks for dependencies (dirs before files)
  5. Add handlers for service restarts
  6. Test with --check --diff
  7. Verify idempotency: second run shows no changes

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.