If you have been around the open source world within the last few years, you would have heard about Red Hat Ansible Automation Platform. If not, think of Ansible as the key to automating the world.
What is Ansible?
Automation! Ansible is automation.
It is an open-source software provisioning, configuration management, and application-deployment tool that is highly customizable through playbooks to meet the needs of the environment
Ansible Core
Ansible Core is the command-line tool that is installed from either community repositories or the official Red Hat repositories for Ansible.
Installation instructions can be found here.
Ansible Tower
Ansible Tower is the Graphical User Interface tool used to execute Ansible tasks. Tower requires a license that is based on the number of systems tower will manage.
Installation instructions can be found here.
How does Ansible work?
Ansible connects over ssh or WinRM (windows) to a remote system to execute a task. Python 2.4+ is a requirement on the remote systems where Ansible will execute its tasks.
Ansible Ad-hoc command
Ansible Core allows ad-hoc commands to be run, or for playbooks to be executed. We will cover playbooks in-depth in another section.
Here is an example of an ad-hoc command that pings ‘localhost’.
ansible localhost -m ping
Here is another example of running an ad-hoc shell command on a remote system:
ansible raleigh -m shell -a 'echo $TERM'
Additional examples and explanations can be found here.
Ansible Playbooks
Ansible playbooks are highly customizable scripts that are used to execute a series of tasks and commands. Below is a basic example of a playbook:
--- - name: My first playbook hosts: localhost tasks: - name: install nginx yum: name: nginx state: present
Defining a playbook
Let’s break down the components of a playbook to understand it better.
name: A description field for the task.
hosts: An indication of where the task needs to be executed.
tasks: A section used to order commands and states that are part of the specific task.
yum: An Ansible module used to manage yum content.
state: Ansible is state-based, which in this playbook, ensures that the Nginx package is present. Different modules support different state parameters.
Running a playbook
Using the above playbook as an example, we will save it as ‘nginx.yaml’.
To run the playbook from Ansible Core, you would execute the following command.
ansible-playbook nginx.yaml
Idempotency
A well-written playbook ensures that even if the playbook is run multiple times, the state will not change from what you wrote it for. For this reason, it is essential to ensure that all tasks in your playbook do not change the system in any way if the change you required has already been applied.
In summary
After reading this introduction to Ansible, you have a good understanding of the basics to get started. You can execute ad-hoc Ansible commands and run very basic playbooks. Understanding the importance of idempotence will serve you well when designing future automation.
Ansible is far more than just a single command; it has enterprise-grade applications like “Ansible Tower” which opens the possibilities to manage hundreds, if not thousands of systems.
The open source community is vast, with many examples out there to use. Use online resources like ansible-galaxy to find Ansible code that’s already been written to accomplish tasks. There is a good chance that the code you are wanting to write has already been written. No need to reinvent the wheel. If you do happen to find reusable code, please remember to give back any fixes or enhancements you make to the community.
Connect with Red Hat Services
Learn more about Red Hat Consulting
Learn more about Red Hat Training
Join the Red Hat Learning Community
Learn more about Red Hat Certification
Subscribe to the Training Newsletter
Follow Red Hat Services on Twitter
Follow Red Hat Open Innovation Labs on Twitter
Like Red Hat Services on Facebook
Watch Red Hat Training videos on YouTube
Understand the value of Red Hat Certified Professionals
Sull'autore
Ken is a senior consultant with the UK&I services team, delivering anything Red Hat. With over ten years of experience, no problem is too big or too small. Happy to help and most importantly learn something new every day.
Ricerca per canale
Automazione
Novità sull'automazione IT di tecnologie, team e ambienti
Intelligenza artificiale
Aggiornamenti sulle piattaforme che consentono alle aziende di eseguire carichi di lavoro IA ovunque
Hybrid cloud open source
Scopri come affrontare il futuro in modo più agile grazie al cloud ibrido
Sicurezza
Le ultime novità sulle nostre soluzioni per ridurre i rischi nelle tecnologie e negli ambienti
Edge computing
Aggiornamenti sulle piattaforme che semplificano l'operatività edge
Infrastruttura
Le ultime novità sulla piattaforma Linux aziendale leader a livello mondiale
Applicazioni
Approfondimenti sulle nostre soluzioni alle sfide applicative più difficili
Serie originali
Raccontiamo le interessanti storie di leader e creatori di tecnologie pensate per le aziende
Prodotti
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Servizi cloud
- Scopri tutti i prodotti
Strumenti
- Formazione e certificazioni
- Il mio account
- Supporto clienti
- Risorse per sviluppatori
- Trova un partner
- Red Hat Ecosystem Catalog
- Calcola il valore delle soluzioni Red Hat
- Documentazione
Prova, acquista, vendi
Comunica
- Contatta l'ufficio vendite
- Contatta l'assistenza clienti
- Contatta un esperto della formazione
- Social media
Informazioni su Red Hat
Red Hat è leader mondiale nella fornitura di soluzioni open source per le aziende, tra cui Linux, Kubernetes, container e soluzioni cloud. Le nostre soluzioni open source, rese sicure per un uso aziendale, consentono di operare su più piattaforme e ambienti, dal datacenter centrale all'edge della rete.
Seleziona la tua lingua
Red Hat legal and privacy links
- Informazioni su Red Hat
- Opportunità di lavoro
- Eventi
- Sedi
- Contattaci
- Blog di Red Hat
- Diversità, equità e inclusione
- Cool Stuff Store
- Red Hat Summit