Ansible is a huge subject, there is no way I can begin to cover all of it in a single post. So, my thinking here, is this will likely contain a number of posts. I usually tend to write simple basic tutorials, but this one will be pretty advanced.
What is ansible? It's a python based automation tool, you can deploy software, change configurations, add users, virtually do anything you can do from the command line. Ok, then if I can already do this from the command line, why do I need ansible?
First of all, it puts it in a repeatable script. Some commands are dangerous. What if I accidentally erase a program, bring down a network interface or delete a user. By scripting it and automating it, I reduce the chances of making mistakes.
Ansible is "the" hot skill today. This is the kind of post that can change someone's career path. If you get a job because of this thread let me know and I'll send you my address so you can send me a commission check every payday
But seriously, this is a skill in high demand right now. Some ansible admins are making anywhere from $150,000 to $200,000 (US) a year.
But the real power in ansible, is not just automation, but enterprise automation. If you are only managing one or two computers, enterprise automation may not make sense for you. But what if you are managing dozens, or hundreds of computers? I could login to all my 50 or computers and add a couple of users by manually by hand, typing in the same commands over and over 50 times and hope I don't make a typing mistake, misspell a password, or misspell their username. Adding a couple of users is just one example, what if I needed to install a program on all 50 computers? Or do a security patching update?
Ansible will let me type in something called a playbook and run it on 50 computers at the same time. I don't have to worry making mistakes on some of them, because they all ran the same exact script. Also, think of how much time this saved me. How long would it take to log in to 50 computers and add users, add patches, and install programs? It could take an entire day or longer. With ansible, I could do this in a few minutes.
I don't really want to spend a lot of time talking about how to install ansible, it's slightly different for different distros. I will breifly mention it here. For my distro it looks like this.
There are more packages I didn't install, and chances are, you won't need all of these. Your distro may name some of these packages slightly differently. The only 3 packages you absolutely need here are ansible, python3-ansible-lint and sshpass. Don't worry about the others for right now. If your distro doesn't have ansible as a package, you can install it with something called pip or pip3.
Warning:: DO NOT mix vendor and pip installs of ansible. Pick one and stick with it. Mixing the two will break things. (ask me how I know)
Once you get those three installed, run this command. For now just run it on your local ansible computer.
This will probably return over 1200 lines of information, this is just some of the stuff ansible know about your computer.
Congratulations, you just ran your first ansible command. This type of output is called json. More about that later.
Now maybe 1200 lines of information is a bit much, what if I just want to see some specific information?
You can filter what you want to see.
You can even put all 3 filters in the same command.
Ok, that's it for today. We haven't even gotten to the fun stuff and playbooks yet.
What is ansible? It's a python based automation tool, you can deploy software, change configurations, add users, virtually do anything you can do from the command line. Ok, then if I can already do this from the command line, why do I need ansible?
First of all, it puts it in a repeatable script. Some commands are dangerous. What if I accidentally erase a program, bring down a network interface or delete a user. By scripting it and automating it, I reduce the chances of making mistakes.
Ansible is "the" hot skill today. This is the kind of post that can change someone's career path. If you get a job because of this thread let me know and I'll send you my address so you can send me a commission check every payday

But the real power in ansible, is not just automation, but enterprise automation. If you are only managing one or two computers, enterprise automation may not make sense for you. But what if you are managing dozens, or hundreds of computers? I could login to all my 50 or computers and add a couple of users by manually by hand, typing in the same commands over and over 50 times and hope I don't make a typing mistake, misspell a password, or misspell their username. Adding a couple of users is just one example, what if I needed to install a program on all 50 computers? Or do a security patching update?
Ansible will let me type in something called a playbook and run it on 50 computers at the same time. I don't have to worry making mistakes on some of them, because they all ran the same exact script. Also, think of how much time this saved me. How long would it take to log in to 50 computers and add users, add patches, and install programs? It could take an entire day or longer. With ansible, I could do this in a few minutes.
I don't really want to spend a lot of time talking about how to install ansible, it's slightly different for different distros. I will breifly mention it here. For my distro it looks like this.
Code:
dnf install -y ansible ansible-builder ansible-collection-ansible-netcommon ansible-collection-ansible-utils ansible-collection-community-general ansible-collection-kubernetes-core ansible-collection-containers-podman ansible-packaging python3-ansible-compat python3-ansible-compat python3-ansible-lint python3-ansible-pylibssh vim-ansible vim-syntastic-ansible ansible-core sshpass
There are more packages I didn't install, and chances are, you won't need all of these. Your distro may name some of these packages slightly differently. The only 3 packages you absolutely need here are ansible, python3-ansible-lint and sshpass. Don't worry about the others for right now. If your distro doesn't have ansible as a package, you can install it with something called pip or pip3.
Warning:: DO NOT mix vendor and pip installs of ansible. Pick one and stick with it. Mixing the two will break things. (ask me how I know)
Once you get those three installed, run this command. For now just run it on your local ansible computer.
Code:
ansible -m setup localhost
This will probably return over 1200 lines of information, this is just some of the stuff ansible know about your computer.
Congratulations, you just ran your first ansible command. This type of output is called json. More about that later.
Now maybe 1200 lines of information is a bit much, what if I just want to see some specific information?
You can filter what you want to see.
Code:
ansible localhost -m setup -a 'filter=ansible_hostname'
Code:
ansible localhost -m setup -a 'filter=ansible_distribution*'
Code:
ansible localhost -m setup -a 'filter=ansible_kernel'
You can even put all 3 filters in the same command.
Code:
ansible localhost -m setup -a 'filter=ansible_hostname,ansible_distribution,ansible_distribution_version,ansible_kernel'
Ok, that's it for today. We haven't even gotten to the fun stuff and playbooks yet.
Last edited: