In this video, we are going to learn how to encrypt strings within a playbook.
So we learn how to encrypt the entire playbook previously.
But do you know that we could actually encrypt strings or words within a playbook?
Yes.
We do not have to go through the entire playbook, securing it.
We could actually use a simple words encrypted using Ansible wall command, and then we could use that
encryption and paste it inside of our playbook.
So let's take an example.
So we will run the command ansible dash wall space, encrypt, underscore string option.
And let's say at this point we want to encrypt the word HTTP.
In this case, for example, you wanted to run a playbook and you do not want to show which package
is being installed.
Clever, right?
So then what we will do is we will write the Ansible World Playbook by and the name of the playbook
would be output by string dynamo.
So you could use a vim command first and then encrypted.
Or you could you use create command, provide the password, so which will encrypt your entire playbook
and then let you edit the file.
All right.
Either way, you pick.
Then what we'll do is we'll define that a a YAML file name of the playbook will be test encrypted output.
The host will be local host.
And then we are adding a variable so we could pass our string through the variable and the string,
the encrypted string that we have is this entire value.
We are putting this entire encrypted value of our http d through our vars variable.
And by the way, when we run this first command, this will output this exact encryption which we will
cover in a second.
So then we will define the task and the task is to print the encrypted string and we'll use the debug
message to show the actual output of that string.
So let's take a look.
Let's go to our Ansible control node and this time I'm going through the Telnet, so through the putty
session.
So this way we will have a bigger screen.
All right.
So very first thing is we'll encrypt the the word HTTP PD, so we'll do ansible, dash, walled and
crypt.
Underscore string is just a word, package word that I picked.
Now you have to specify the password.
All right.
You see, as soon as you run the command, you are given the walled encryption.
So this is the entire encryption which translates into HTTP.
So we are now going to write the HTTP package.
Instead, we will take this value, this encrypted value, and we will paste that inside of the playbook.
All right.
So I have already created a playbook earlier and I called it output by string yaml.
All right.
So let's take a look at our playbook.
I am in Etsy Ads Playbooks Directory and the file name is a put by string.
Here it is.
This is a file that can be viewed by anyone.
You see?
You could see the file because I did not encrypt the entire playbook.
I just used the Vim command earlier, created the playbook, and simply pasted this entire value from
here all the way to here right after this variable.
And the variable I have named secret you can pick any name is just a secret that I picked.
All right.
Now, what I will do is I will run this command.
Sorry, I will run the Ansible playbook command with the ask option.
So we could run this playbook.
So for that, we'll do ansible dash playbook.
And the name of the playbook is output dash output by a string dynamo.
And then dash, dash.
Ask Walt Dash.
Pass.
So this same option will be used if you have encrypted the entire playbook or if you have encrypted
just a string.
All right.
Let's go ahead and hit enter.
Now it will ask you for the password that you used when you encrypted that string.
Okay.
Decryption failed.
No walls.
Secrets were found that could be decrypted.
I did not provide the correct password when it asked me for the world password.
So let me run it again.
Now let me provide the right password.
Okay.
All right.
So it ran.
This is the point where it ran.
And right here, you see it says where I wanted the encryption, the actual word or string to be displayed
here on the debug module.
And the variable that I'm using is the secret, which is pointing back to the variable.
And the variable is saying I am a container and I have this value.
All right, I'm saying display this value and it is displaying and instead of entire encryption, it
is giving me the string value because I have already provided the password.
So it could be decrypted and it could show me the actual string.
That's how the string works, where you could encrypt a single string or multiple strings together and
you could paste that inside of your playbook.
So you do not have to encrypt the entire playbook.