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