hs_rohit
hs_rohit

Reputation: 103

How to password protect a file in remote system using ansible?

I'm trying to password protect a text file in a remote system, using mcrpyt or openssl, but these shell commands require a prompt for providing passwords. How do i make this possible using ansible

Upvotes: 1

Views: 458

Answers (1)

hs_rohit
hs_rohit

Reputation: 103

I found a way to do it using the openssl command

echo -n "your-password" | openssl enc -aes-256-cbc -salt -in input -out output.enc -pass stdin

To decrypt

echo -n "your-password" | openssl enc -d -aes-256-cbc -in output.enc -out file -pass stdin

Just write these commands in ansible and you can use the password from templates, where you can encrypt it using the ansible vault

For example

echo -n "{{ password }}" | openssl enc -d -aes-256-cbc -in output.enc -out file -pass stdin

You can get this passwrod as avariable from your var file which can be encrypted using ansible vault

Upvotes: 1

Related Questions