This blog post covers a brief overview of the topics covered and some common questions asked during Day 1 Live Interactive training on Ansible for Beginners.
During our Day 1 Live Session, we covered Introduction to Ansible, Ansible Inventory & Ad hoc commands Basics of Ansible Playbook and performed Lab1, Lab2, Lab3, Lab4, Lab5 from 9 Hands-On Labs
Automation
Ansible is a radically simple IT automation engine that automates cloud provisioning, configuration management, application deployment, intra-service orchestration, and many other IT needs.
Ansible
Q1. Explain the Ansible Architecture?
Ans. The Ansible Automation Engine consists of:
Ans. There are mainly two important components of ansible:
Q4. What are the features of using Ansible?
Ans. The features of using ansible are:
Human Readable:
Q5. Where should I use Ansible?
Ans. We use ansible in the following ways:
- Provisioning: Provisioning is creating new infrastructure. Ansible allows for application management, deployment, orchestration, and configuration management.
- Continuous Delivery: Ansible provides a simpler way to automatically deploy applications. All required services for a deployment can be configured from a single system. Continuous Integration (CI) tool can be used to run Ansible playbook which can be used to test and automatically deploy the application to production if tests are passed.
- Application Deployment: Ansible provides a simpler way to deploy applications across the infrastructure. Deployment of multi-tier applications can be simplified and the infrastructure can be easily changed over time.
- Configuration management: Centralizing configuration file management and deployment is a common use case for Ansible, and it’s how many power users are first introduced to the Ansible automation platform.
- Security automation: When you define your security policy in Ansible, scanning, and remediation of site-wide security policy can be integrated into other automated processes and instead of being an afterthought, it’ll be integral in everything that is deployed.
- Orchestration: Configurations alone don’t define your environment. You need to define how multiple configurations interact and ensure the disparate pieces can be managed as a whole. Out of complexity and chaos, Ansible brings order.
Ansible Configuration
[Defaults] #inventory file location inventory = ./inventory #which user credential ansible has to use to connect to host remote_user = someuser #whether it should ask for "someone password" ask_pass = false [privilege_escalation] #enable privilege escalation become = true #set to use sudo for privilege escalation become_method = sudo #privilege escalation user become_user = root #enable prompting for the privilege escalation password become_ask_pass = true
Inventory
Q6. What is Static and Dynamic Inventory with examples?
Ans. Static Inventory: In Ansible, a static inventory file is a plain text file that contains a list of managed hosts declared under a host group using either hostnames or IP addresses.
[webservers] 173.82.115.165 [database_servers] 173.82.220.239 [datacenter:children] webservers database_servers
Dynamic I
{ "webservers": { "hosts": [ "webserver1.example.com", "webserver2.example.com" ], "vars": {} }, "database_servers": { "hosts": [ "mysql_db1", "mysql_db2" ], "vars": {} }, "_meta": { "hostvars": { "mysql_db2": {}, "webserver2.example.com": {}, "webserver1.example.com": {}, "mysql_db1": {} } } }
Ad-hoc Commands
Basics of Ansible Playbook
--- - name: This installs and starts Apache webserver hosts: webservers tasks: - name: Install Apache Webserver yum: name=httpd state=latest - name: check httpd status service: name=httpd state=started
--- - hosts: webservers vars: http_port: 80 max_clients: 200 remote_user: root tasks: - name: ensure apache is at the latest version yum: pkg=httpd state=latest - name: replace default index.html file copy: src=/static_files/index.html dest=/var/www/html/ mode=0644 notify: - restart apache - name: ensure apache is running (and enable it at boot) service: name=httpd state=started enabled=yes handlers: - name: restart apache service: name=httpd state=restarted
Q/A’s from Day 1 live session:
These are some questions that were asked during the Ansible for Beginners day 1 live session. These questions are from Modules 1 & 2.
Q1. Is ansible a RedHat Product?
Ans. Yes, Ansible is a RedHat product, but it is open-source.
Q2. Can we use Ansible in Windows?
Ans. Ansible control node can be installed only on a Linux machine, but it can manage Windows nodes via Windows Remote Management.
Q3. What is the Ansible control node?
Ans. A control node is a Linux server with Ansible installed on it and is used to manage remote hosts or nodes. These remote systems are known as Managed Hosts or Managed nodes.
Q4. What is Module in Ansible?
Answer: A module is a reusable, standalone script that Ansible runs on your behalf, either locally or remotely. Modules interact with your local machine, an API, or a remote system to perform specific tasks like changing a database password or spinning up a cloud instance.
Q5. What is ansible.cfg file?
Answer: This is the brain and the heart of Ansible, the file that governs the behavior of all interactions performed by the control node. In Ansible’s case, that default configuration file is (ansible. cfg)
Q6. What is EPEL?
Ans. EPEL stands for Extra Package for Enterprise Linux. The EPEL repository is a community-supported repository hosted by the Fedora Community project. The EPEL repository is not a part of Red Hat.
Q7. What is the difference between static & dynamic inventory?
Ans. In Ansible, a static inventory file is a plain text file that contains a list of managed hosts declared under a host group using either hostnames or IP addresses.
In a configuration – especially a cloud setup such as AWS where the inventory file keeps constantly changing as you add or decommission servers, keeping tabs on the hosts defined in the inventory file becomes a real challenge. It becomes inconvenient to go back to the host file and update the hosts’ list with their IP addresses. And this is where a dynamic inventory comes to play
Q8. If we add new code to the Ansible configuration does the server need a reboot?
Ans. No, configuration changes are applied using ansible binary & the OS does not need a reboot.
Q9. What is the Ansible playbook?
Ans. An Ansible playbook is a blueprint of automation tasks—which are complex IT actions executed with limited or no human involvement. Ansible playbooks are executed on a set, group, or classification of hosts, which together make up an Ansible inventory.
Q10. Do all managed nodes require python?
Ans. Yes, all managed nodes require python to be managed by Ansible.
Quiz Questions!
Check out these questions and see if you can answer them
a. JSON format
b. YAML format
c. XML format
d. HTML format
Comment your answer in the comment box.
The right answer will be revealed in my next week’s blog.
References
- Ansible tutorial
- Ansible for beginners step-by-step activity guides hands-on-lab
- Ansible for Beginners | Overview | Architecture & Use Cases
Next Task For You
If you are considering in-depth learning about Ansible in the coming days, then do join our WAITLIST and don’t miss an opportunity to attend a free class and gain a plethora of insights on the basics of Ansible.
The post Ansible for Beginners Day1 Live Session Review and Q/A appeared first on Cloud Training Program.