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
저자 소개
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.
채널별 검색
오토메이션
기술, 팀, 인프라를 위한 IT 자동화 최신 동향
인공지능
고객이 어디서나 AI 워크로드를 실행할 수 있도록 지원하는 플랫폼 업데이트
오픈 하이브리드 클라우드
하이브리드 클라우드로 더욱 유연한 미래를 구축하는 방법을 알아보세요
보안
환경과 기술 전반에 걸쳐 리스크를 감소하는 방법에 대한 최신 정보
엣지 컴퓨팅
엣지에서의 운영을 단순화하는 플랫폼 업데이트
인프라
세계적으로 인정받은 기업용 Linux 플랫폼에 대한 최신 정보
애플리케이션
복잡한 애플리케이션에 대한 솔루션 더 보기
오리지널 쇼
엔터프라이즈 기술 분야의 제작자와 리더가 전하는 흥미로운 스토리
제품
- Red Hat Enterprise Linux
- Red Hat OpenShift Enterprise
- Red Hat Ansible Automation Platform
- 클라우드 서비스
- 모든 제품 보기
툴
체험, 구매 & 영업
커뮤니케이션
Red Hat 소개
Red Hat은 Linux, 클라우드, 컨테이너, 쿠버네티스 등을 포함한 글로벌 엔터프라이즈 오픈소스 솔루션 공급업체입니다. Red Hat은 코어 데이터센터에서 네트워크 엣지에 이르기까지 다양한 플랫폼과 환경에서 기업의 업무 편의성을 높여 주는 강화된 기능의 솔루션을 제공합니다.