But because I added a line in Ansible config to ask for the vault pass,
I'm being prompted. Now how you want to handle this in your practice,
there's just too many options.
I'd have to know more about your situation.
But it's a good habit to get into dealing with that vault password to decrypt
the vault and therefore have access to the service account credentials when you
need them without ever displaying the plain text.
So without the verbose, it looks a lot easier.
It's a lot easier to parse for sure.
And it's telling you what will happen.
And if the machine is already set up, it doesn't need anything.
It looks like the print autostart tasks really went
sideways where we've got a lot of red, ugly text.
And this is a case where myself, I use generative AI, to be honest with you.
I'll select the error text and throw it into GitHub
Copilot or ChatGPT or I use Google Bard.
The only thing I would advise against is be careful to ensure that you don't
have any sensitive or proprietary data in that output because depending upon
which generative AI tool you're asking for help,
well, that could lead to some issues.
In our issue,
what we could do also is either comment out or remove the offending play.
In my case, for simplicity, I'm going to get rid of that play altogether.
And let me make sure to save that.
When I'm in WSL, it won't let me save as root normally.
So remember, in a previous module,
I showed you that save as root in WSL extension,
so we can run that.
And then when we're ready,
we can do an ansible‑playbook test and just let it
run after I supply the password.
Now nothing I'm doing in this particular playbook actually requires elevation,
so it's a little bit anticlimactic.
Let me show you a couple more examples here that do require that.
In fact, one example,
I've got a playbook called elevation.yml that's going to
install 7‑Zip on the target nodes.
So in this playbook, we have one play called Install Software.
We're not going to gather facts for this run.
And notice that I'm explicitly adding a vars_files element here where I path.
Now do I need that?
Not necessarily.
Because in my ansible.cfg, I've got it here.
But again, in the name of best practice and boilerplate,
you might have in your playbook templates a reference to
your vars_file because we're going to need,
in this case, the Ansible user and the Ansible password.
In our install 7‑Zip task, that uses the win_package module.
It's asking where's the executable or, in this case,
the MSI package, and what is the desired state present?
Now, here's the elevation stuff that you need to know right here.
Become: yes.
In other words, elevate.
The become method is not sudo but runas because we're in Windows.
The become_user is going to be the value of ansible_user in our vault file,
which I know is Tim.
And then for the become_password, we're grabbing that as a variable,
and that is going to be the ansible_password value that's in the file.
Now, you could also have a separate‑‑‑ Normally,
the ansible_password and the ansible_become password are the same value.
So in this case, line 17 works exactly as it is.
Okay, good.
Third example, because I see we're starting to run short on time a little bit,
the notion of gathering facts.
You might wonder, well,
what are all these different facts that can be gleaned on our Windows host?
So I figured why not create a simple playbook that
reports on at least some of the major ones.
And this is an example, which we'll get into later formally,
of how to integrate Ansible using the Jinja2 templating engine because
what's happening here is we're going to obviously gather facts because
that's the whole purpose of this report. And we're going to do a setup,
which is just simply gathering facts.
And then we're going to use the template module, built‑in module, using the
facts_template Jinja template as our structure, and write out the file with
results into my home folder with the file name being report_ and then the
host name of each machine .csv.
The J2 file looks relatively straightforward.
This is what Jinja markup looks like.
We've got our column headers, host name,
OS, OS version,
etc., and then we're plugging in or substituting or interpolating, however you
want to say that, the values for various key Ansible facts.
So, that's the deal with that one.
Let's try running that one before we end the demo.
Let me clear the screen again, and let's do an
ansible‑playbook, and the name is elevation.
Let me also make sure that these files are saved.
Let me do a Command Palette, Save as Root.
Let me go back here, bring up Command Palettte, and Save as Root just
to make sure that I've saved it. Again, this warning is annoying, but
I'm only getting prompted for the password automatically because I
specified it in my config. Again, we could, using ad hoc commands,
we could throw in ‑‑ask_vault_password as well.
So at this point,
both of our Windows machines should actively be undergoing an
installation of 7‑Zip as long as that URL works.
Yeah, it looks like it happened on both of those machines. It got changed.
And if I open the Start menu, there's 7‑Zip file manager right now.
Pretty easy, huh?
I hope you're as impressed as I have been
historically with how elegant Ansible is.