1

I have a .json file which I have successfully encrypted with ansible vault:

{
  "database": {
    "username": "root",
    "password": "mypassword",
    "host": "127.0.0.1:3306",
    "name": "database"
  }
}

Encrypted with: ansible-vault encrypt config.json

Run ansible playbook with: ansible-playbook -i hosts playbook.yml --ask-vault-pass

Enter the same password and the playbook runs but the files aren't unencrypted on the server.

Any ideas?

Elliot Reeve
  • 901
  • 4
  • 21
  • 39

1 Answers1

1

Unfortunately you can't simply encrypt files and then transfer them over. There are a few github issues about this, but ultimately the solution is that you have to store encrypted contents of a file in a variable or use the lookup plugin to get the file contents and put them remotely.

The encrypted variable should be self-explanatory. Here's a quick example of using the lookup plugin:

- copy: 
    content: "{{ lookup('file', 'files/deepest/darkest/secrets') }}" 
    dest: /remote/unencrypted/destination
Dan
  • 1,925
  • 3
  • 22
  • 28