All jobs

Move Plaintext Passwords in Ansible Playbooks Into Ansible Vault

Yes. An agent finds the passwords your Ansible playbooks keep in plain text, moves them into encrypted vault files, and opens a pull request that still runs.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent clones the repository into its own cloud sandbox and searches it before it changes anything: every password, secret and token key in YAML, every literal credential in a Jinja template, every ansible.cfg and every Vagrantfile that runs a playbook. In a repository like geerlingguy/ansible-for-devops it finds lamp-infrastructure/playbooks/db/vars.yml, where mysql_replication_user has password: secret; lamp-infrastructure/playbooks/db/main.yml, where a pre_tasks set_fact builds mysql_users with password: secret twice, one entry per host in groups['lamp_www']; lamp-infrastructure/playbooks/www/templates/index.php.j2, where mysql_test_connection() hardcodes $password = 'secret'; drupal/provisioning/playbook.yml, where the mysql_user task sets password: "1234" for the {{ domain }} user; and deployments/playbooks/vars.yml, where app_secrets holds three hex keys for dev, test and prod that deploy.yml writes into config/secrets.yml through templates/secrets.yml.j2.

It also reads how the playbooks are run, because a vault changes that. lamp-infrastructure/ansible.cfg has host_key_checking = False, roles_path = ./roles, nocows = 1, retry_files_enabled = False and pipelining = True, and no vault_password_file. The Drupal Vagrantfile sets ansible.playbook = "provisioning/playbook.yml". .github/workflows/ci.yml runs a matrix of playbooks (drupal.yml, docker.yml, elk.yml, security.yml, solr.yml and others) through a downloaded tests/test.sh shim, while lamp-infrastructure.yml and deployments.yml are commented out as not testable in CI. So of the files with secrets, only the Drupal playbook runs in CI today.

The agent follows the convention from the Ansible documentation: a vault.yml next to each vars.yml, holding vault_-prefixed variables, encrypted with ansible-vault encrypt, and the plain variables pointing at them. mysql_replication_user.password becomes "{{ vault_mysql_replication_password }}", the two set_fact entries read "{{ vault_mysql_app_password }}", the Drupal mysql_user task reads "{{ vault_drupal_db_password }}" from a new drupal/provisioning/vault.yml loaded through vars_files, and app_secrets moves whole into deployments/playbooks/vault.yml. The literal in index.php.j2 becomes {{ mysql_app_password }}, so the template renders the same value the database task sets. The values inside the vaults stay what they were (secret, 1234, the three keys), so every playbook behaves exactly as before, and the pull request lists them as credentials to rotate, since they remain readable in git history.

The vault password never touches the repository. The reader saves it as a Project secret in the console, and the run starts in that Project, so the agent reads it as an environment variable and passes it to ansible-vault with --vault-password-file pointing at a file outside the checkout. It adds vault_password_file to the Vagrant provisioner block and documents a ~/.ansible/a4d-vault-pass convention in each affected README. For CI, it adds a step to ci.yml that writes ${{ secrets.ANSIBLE_VAULT_PASSWORD }} to a file and exports ANSIBLE_VAULT_PASSWORD_FILE before tests/test.sh runs, reads the shim to see whether that variable reaches the ansible-playbook call inside its container, and says in the pull request if it does not. Then it runs ansible-playbook --syntax-check on every changed playbook and ansible-vault view on every vault file with the password, and confirms git grep finds none of the old literals outside history.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Move every plaintext credential in this Ansible repository into Ansible Vault. Search all YAML, templates and config for passwords, secrets, tokens and keys, and list what you find with file and line before changing anything. For each playbook, create an encrypted vault.yml beside its vars with vault_-prefixed variables, point the existing variables at them, replace literals in templates with variables, and keep every value unchanged so the playbooks still run. The vault password is in the ANSIBLE_VAULT_PASSWORD environment variable; never write it into the repository. Update ansible.cfg, Vagrantfiles, READMEs and the CI workflow so each knows where the password comes from. Run a syntax check on every changed playbook and confirm no old literal remains. Open a pull request that lists each moved secret and each value that should be rotated.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch that adds encrypted vault.yml files (their contents show only as $ANSIBLE_VAULT;1.1;AES256 blocks), changes the vars.yml, playbook and template files that referenced the literals, the Vagrantfiles that run them, ansible.cfg, the affected READMEs and .github/workflows/ci.yml. Its description is a table: each secret, where it was, which vault variable now holds it and whether the value should be rotated.

The run's record keeps the search that found the literals, the ansible-vault commands (without the password), the syntax checks and the final git grep that came back empty, so a reviewer can see the agent looked everywhere and not only in the obvious vars.yml files.

Before merging, a reviewer confirms the vault password is stored where the team keeps shared secrets, adds the ANSIBLE_VAULT_PASSWORD repository secret for CI, checks that any playbook the agent could not run in CI still has a documented way to supply the password, and schedules the rotation of the values that now live in git history.

Run it on every secret found in a playbook

This is team work: someone has to hold the vault password and decide what gets rotated. Start the run from the console in the Project that holds the password as a secret, and let the agent's first message, the list of what it found, go to the channel where the team reads it. A teammate answers with a follow-up (POST /o/{org}/sessions/{id}/messages) to say which values are real and which are sample data that can stay, and the agent continues from there.

To catch new plaintext secrets later, an automation in the same Project with a schedule trigger (cron for Monday morning in your timezone) runs the same prompt weekly and opens a pull request only when it finds something; a week with nothing to move ends with a one-line answer and no branch.

The use case this job follows, with its automation and trigger: Steer a run as a team.

Why run it on Rush?

Vaulting secrets by hand is tedious in exactly the way that causes mistakes: a literal left in a template, a set_fact that still builds the password inline, a Vagrantfile that no longer runs because nobody told it where the password is. The agent searches the whole tree, keeps values identical so nothing breaks, and runs the syntax checks and the final grep in its own sandbox, with the output kept in the run's record.

The vault password reaches the sandbox as a Project secret and nowhere else: not in the prompt, not in the pull request, not in the transcript. The sandbox parks when the turn ends and is released after seven idle days. Several repositories can be swept at once, each in its own sandbox, and each pull request shows what moved and what to rotate.

Frequently asked questions

Where does the vault password come from?

From a Project secret you save in the console. The run starts in that Project and reads the secret as an environment variable. The agent writes it to a file outside the checkout for --vault-password-file, and that file is destroyed with the sandbox. It never appears in the repository or the pull request.

Will my playbooks still work after the change?

Yes. Each vault holds the same value the plaintext variable held, and the plain variable now references the vault variable. Running the playbook with the vault password produces the same result as before. The agent runs ansible-playbook --syntax-check on every changed playbook to prove the YAML and references resolve.

Why does it ask me to rotate values it kept the same?

Because a value that was ever committed in plain text is in git history, and encrypting the current file does not remove it. The pull request lists each such value so you can rotate it after merging. Sample data like a tutorial's 1234 is listed too, and you can say it stays.

Does it work with inline encrypted strings instead of vault files?

Yes. If you prefer ansible-vault encrypt_string values inside the existing vars.yml, say so in the prompt. The agent defaults to separate vault.yml files with the vault_ prefix because grep still finds every variable name and a diff of vars.yml stays readable.

What about CI runs that need the password?

The agent adds a workflow step that writes a repository secret to a file and exports ANSIBLE_VAULT_PASSWORD_FILE. You add the secret in the repository settings. Where a test harness runs Ansible inside a container, the agent checks whether the variable reaches it and says in the pull request if it needs a change it could not verify.

More Ansible jobs

More jobs like this: Steer a run as a team

Keep reading