Introduction to Ansible Transcripts
Chapter: Ansible Core Concepts
Lecture: Running Ad Hoc Tasks

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Let's use this example Ansible task and run it using the Ansible Ad-Hoc mode. Move over into your Mac or Linux environment
0:07 where you're planning to work with Ansible. First we're going to test and were going to see that Git is not installed on our system.
0:13 We do want to use Ansible to install it. Remember that you need to keep your virtualenv activated. So, use the source command
0:19 point it to your virtualenv, then activate. You can use the pip freeze command to make sure that Ansible is actually installed.
0:28 In this case, yes it is we're using version 2.6.2 Now let's run a couple of Ad-Hoc commands.
0:33 We're just going to run these against our localhost system. And the first one is just to gather the facts. Now what do we mean by facts.
0:38 A fact is a piece of data that Ansible gathers on the system before working with it. Ansible gathers a wide range of information.
0:46 So that it knows how to take the actions specified in an Ad-Hoc command or in a Playbook. And we can see all the facts that Ansible gathers.
0:54 Use this command: ansible localhost -m setup. This isn't going to apply any action. It will only gather the facts about our system.
1:02 Now I put in localhost as a placeholder. We don't have a hosts file. Ansible will tell us that you couldn't find a host file.
1:08 But it will gather the facts for our localhost system. When you execute that command, you're going to see
1:13 a whole bunch of information about your current system. Ansible will do this every time it runs. For our next Ad-Hoc command type in ansible localhost
1:23 as we just did, in the previous command and this time with -m specify the A-P-T apt module. Specify -a and pass in, name=git-core
1:33 state=present, update_cache=yes specify -b, which explicitly states we wana use our superuser privileges in order to execute this command
1:43 since we're installing a system wide package. Specify -K, which will force Ansible to ask you for your superuser password
1:51 and then one final argument, which is -e where we set an additional variable which is the ansible_Python_interpreter=/usr/bin/Python3
1:59 explicitly set as /usr/bin/Python3. In this case, this is to prevent Ansible from using the default Python 2 installation
2:06 which does not have Ansible installed. Once you've got all that typed in, go ahead and hit execute. Now we're good to go.
2:20 We have Git installed, we can use it on our system. So we just ran a couple of Ansible Ad-Hoc tasks. For the remainder of these videos
2:27 we're going to run tasks through Playbooks. That's how you can run individual tasks if you want to test out a module
2:33 or just do something quick from the command line.

Talk Python's Mastodon Michael Kennedy's Mastodon