How to use ansible-vault encrypt_string

I’m trying to encrypt a password to use in a playbook but I don’t understand what the parameters mean when running the encrypt string command.

Let’s say my password is Password!123

Do I run the command like this?

[root@server1 ~]$ ansible-vault encrypt_string --vault-id topsecret.yaml ‘Password!123’ --name ‘Password!123’
Password!123: !vault |
$ANSIBLE_VAULT;1.1;AES256
31636462383335363735326162373334356662306565343666623437356662326263376334626435
3930336636343032303933326664623434306331396261390a383730353565303033366238643630
38326663323636633265383531396230623238306239323365366237393731316130346132386434
3738386364393966660a353663373936366637626632616166383139373933343962323466353265
6265

Then place this in the playbook?

  • name: show version
    hosts: bigip1
    connection: local

tasks:

  • name: show version
    bigip_command:
    commands:
  • show sys version
  • show sys clock
    server: “{{ inventory_hostname }}”
    password: !vault |
    $ANSIBLE_VAULT;1.1;AES256
    31636462383335363735326162373334356662306565343666623437356662326263376334626435
    3930336636343032303933326664623434306331396261390a383730353565303033366238643630
    38326663323636633265383531396230623238306239323365366237393731316130346132386434
    3738386364393966660a353663373936366637626632616166383139373933343962323466353265
    6265
    user: “admin”
    validate_certs: “no”

When I try this I receive a FAILED! => {“msg”: “Attempting to decrypt but no vault secrets found”} error.

Thanks,

You need to provide the password file so Ansible can encrypt the vault string.
  --vault-id topsecret.yaml