Ansible Tutorials and Notes Nov 2023

What is Ansible?

Why Ansible?

Ansible Architecture?

What is module?

What is Plugins?

What is Ansible?
=========================
	Config mgmt tool
	Release
		Community ----------------------- cmd = free 
		AWX
		Tower === Automation Platform = Paid
	Dev in python
	by Redhat
	version


What is Config?
	SERVER(S)

Whats there in SERVER?
---------------------
Resources		action
file			C U D
Dir			C U D
Package			INS RE UP
Services		E D S S RE
user
group
bash
cmd
=====================================
Why Ansible?
	BASH -- Windows?
	PS  ---- Linux?
	------------------------------
	All platform

	JAVA
	PYTHON --> 30 Days

	DIFF to learn - debug - extend - share - test - 
	DSL --> Ansible

	IDEOMPOTENT
	1st  - 10 STEPS ----- 1 mins ------- - 10mins
	2nd  ---- 1 change --- 1 mins --------- 1 mins
	===================

Other tool - 
	Chef - Puppet - Cfengine - Salt
	Udeploy - Octo Deploy
	

=====================================================================
Ansible Architecture

HUMAN ---> ACS  -------------> ARS(S)

---> ACS  -------------> ARS(S)
Ansible			NOTHING
    Linux64		ANY

    ---------------> SSH----> Linux
     -------------> Winrm -----> Windows
============================================
Components of Ansible
============================================
Ansible 
	Excutables
	Modules   -> A python Code -> Reside in ACS --> Run in ARS
			copy, file, package, service, bash. Require param
	https://docs.ansible.com/ansible/2.9/modules/list_of_all_modules.html
	https://docs.ansible.com/ansible/2.8/modules/modules_by_category.html

	Plugins	  
		CORE
		External
		-> A python Code -> Reside in ACS --> Run in ACS
	Configfile	config file = /etc/ansible/ansible.cfg


	/usr/bin/ansible
			ssh port - 22(default)
	config file = /etc/ansible/ansible.cfg
			port - 23
	
Ansible Tutorials: Example of ansible.cfg
inventory Playbook ACS - 54.85.203.183 ARS1 - 54.174.239.89 ARS2 - 34.226.195.116 =======================================
Ansible Training Flow
CMD Or Script ======================================================= Project ======================================================= Setup a webserver. Psucode -------------------- Step 1 - Install Apache in ubuntu apt Step 2 - Copy package(index.html) into /var/www/html/index.html copy Step 3 - Start Service service ======================================================

ansible localhost -m apt -a"state=latest name=apache2"
ansible localhost -m copy -a"src="index.html" dest="/var/www/html/index.html"
ansible localhost -m service -a"name=apache2 state=started"


ansible all -i 54.174.239.89,34.226.195.116, -m apt -a"state=latest name=apache2" -u ubuntu --key-file=node.pem -b
ansible all -i 54.174.239.89,34.226.195.116, -m copy -a"src=index.html dest=/var/www/html/index.html" -u ubuntu --key-file=node.pem -b
ansible all -i 54.174.239.89,34.226.195.116, -m service -a"name=apache2 state=started" -u ubuntu --key-file=node.pem -b



GROUP of inventory
----------------------
all


ansible all -i 54.174.239.89,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116,34.226.195.116, -m apt -a"state=latest name=apache2" -u ubuntu --key-file=node.pem -b


inventory
54.85.203.183
54.174.239.89
34.226.195.116


ansible all -i inventory -m apt -a"state=latest name=apache2" -u ubuntu --key-file=node.pem -b
ansible all -i inventory -m copy -a"src=index.html dest=/var/www/html/index.html" -u ubuntu --key-file=node.pem -b
ansible all -i inventory -m service -a"name=apache2 state=started" -u ubuntu --key-file=node.pem -b


inventory

[web]
54.85.203.183
54.174.239.89

[db]
34.226.195.116


ansible web -i inventory -m apt -a"state=latest name=apache2" -u ubuntu --key-file=node.pem -b
ansible web -i inventory -m copy -a"src=index.html dest=/var/www/html/index.html" -u ubuntu --key-file=node.pem -b
ansible web -i inventory -m service -a"name=apache2 state=started" -u ubuntu --key-file=node.pem -b

ansible web,db -i inventory -m apt -a"state=latest name=apache2" -u ubuntu --key-file=node.pem -b
ansible web,db -i inventory -m copy -a"src=index.html dest=/var/www/html/index.html" -u ubuntu --key-file=node.pem -b
ansible web,db -i inventory -m service -a"name=apache2 state=started" -u ubuntu --key-file=node.pem -b

Assignment

Ansible Playbook Variable Template Handlers

Playbook
======================
	a yaml file 
	Contains
		PLAYS
		Vars
		Templates
		Hands
		Cond

What is Play?
----------------
	Section
	 	Hosts: Localhost OR All or WEB
		Tasks:
			Task1
			Task2

What is Play?
----------------
	Section
	 	Hosts: Localhost OR All or WEB
		Tasks:
			Module1 and its param
			Module2 and its param
			Module2 and its param
			Module2 and its param
======================================================

---
- name: Update web servers
  hosts: localhost

  tasks:



ansible web,db -i inventory -m apt -a"state=latest name=apache2" -u ubuntu --key-file=node.pem -b
ansible web,db -i inventory -m copy -a"src=index.html dest=/var/www/html/index.html" -u ubuntu --key-file=node.pem -b
ansible web,db -i inventory -m service -a"name=apache2 state=started" -u ubuntu --key-file=node.pem -b

---
- name: Update web servers
  hosts: localhost

  tasks:
  - name: Install apache Apache2
    ansible.builtin.apt:
      name: apache2
      state: present
  - name: Copy file with owner and permissions
    ansible.builtin.copy:
      src: index.html
      dest: /var/www/html/index.html
  - name: Start service apache2, if not started
    ansible.builtin.service:
      name: apache2
      state: started


ansible-playbook web.yaml
ansible-playbook web.yaml -u ubuntu --key-file=node.pem -b
ansible-playbook -i inventory web.yaml -u ubuntu --key-file=node.pem -b


Variables
https://www.devopsschool.com/blog/example-code-of-ansible-variable-with-playbook/

---
- name: Update web servers
  hosts: localhost
  vars_files:
    - "vars.yaml"
  vars_prompt:
    - name: "version"
      prompt: "Which version Do you want to install?"
      private: no


  tasks:
  - name: Install apache Apache2
    ansible.builtin.apt:
      name: "{{ packagename }}"
      state: present
  - name: Copy file with owner and permissions
    ansible.builtin.copy:
      src: index.html
      dest: /var/www/html/index.html
  - name: Start service apache2, if not started
    ansible.builtin.service:
      name: "{{ servicename }}"
      state: started
  - name: Print return information from the previous task
    ansible.builtin.debug:
      var: myname
  - name: Print return information from the previous task
    ansible.builtin.debug:
      msg: "My Name is {{ myname }} and My age is {{ age }}"
  - name: Print return information from the previous task
    ansible.builtin.debug:
      msg: "version is {{ version }}"




Ansible Template
Ansible Template and Handlers explained with Example
--- - name: Update web servers hosts: localhost vars: myname: "Rajeshkumar" age: "17" packagename: "apache2" servicename: "apache2" port: 81 vars_files: - "vars.yaml" vars_prompt: - name: "version" prompt: "Which version Do you want to install?" private: no tasks: - name: Install apache Apache2 ansible.builtin.apt: name: "{{ packagename }}" state: present - name: Template index.html template: src: index.html.j2 dest: /var/www/html/index.html - name: Start service apache2, if not started ansible.builtin.service: name: "{{ servicename }}" state: started - name: Print return information from the previous task ansible.builtin.debug: var: myname - name: Print return information from the previous task ansible.builtin.debug: msg: "My Name is {{ myname }} and My age is {{ age }}" - name: Print return information from the previous task ansible.builtin.debug: msg: "version is {{ version }}" - name: Template index.html template: src: ports.conf.j2 dest: /etc/apache2/ports.conf - name: Start service apache2, if not started ansible.builtin.service: name: "{{ servicename }}" state: restarted Ansible Handlers
Ansible Template and Handlers explained with Example
--- - name: Update web servers hosts: localhost vars: myname: "Rajeshkumar" age: "17" packagename: "apache2" servicename: "apache2" port: 81 vars_files: - "vars.yaml" vars_prompt: - name: "version" prompt: "Which version Do you want to install?" private: no tasks: - name: Install apache Apache2 ansible.builtin.apt: name: "{{ packagename }}" state: present - name: Template index.html template: src: index.html.j2 dest: /var/www/html/index.html - name: Start service apache2, if not started ansible.builtin.service: name: "{{ servicename }}" state: started - name: Print return information from the previous task ansible.builtin.debug: var: myname - name: Print return information from the previous task ansible.builtin.debug: msg: "My Name is {{ myname }} and My age is {{ age }}" - name: Print return information from the previous task ansible.builtin.debug: msg: "version is {{ version }}" - name: Template index.html template: src: ports.conf.j2 dest: /etc/apache2/ports.conf notify: Start service apache2, if not started handlers: - name: Start service apache2, if not started ansible.builtin.service: name: "{{ servicename }}" state: restarted ================================================== --- - name: Update web servers hosts: localhost vars: myname: "Rajeshkumar" age: "17" packagename: "apache2" servicename: "apache2" port: 81 vars_files: - "vars.yaml" vars_prompt: - name: "version" prompt: "Do you want to restart. Type yes or no" private: no - name: Starting a Apache Server ansible.builtin.service: name: httpd state: started when: - version == "yes"

Ansible Roles

Ansible Role
================================
is DIRECTORY
	for What?
To manage your code
	Enabled sharing code
	Reusing

root@ip-172-31-52-57:/home/ubuntu/web# tree
.
├── README.md
├── defaults
│   └── main.yml			VARS
├── files
			index.html
├── handlers
│   └── main.yml			tasks but handlers
├── meta
│   └── main.yml			name - lice - copy - dep
├── tasks
│   └── main.yml			tasks
├── templates
			port.conf.j2
├── tests
│   ├── inventory
│   └── test.yml
└── vars
    └── main.yml			VARS

8 directories, 8 files

=======================================================
PROJECT

	Module1 - role1

	Moudle2 - role2

	Module3 - role3
==============================================

https://www.devopsschool.com/blog/ansible-role-project-1/

---
- name: Update web servers
  hosts: localhost
  roles:
    - web


   75  ansible-galaxy init role web
   76  ansible-galaxy
   77  ansible-galaxy role web
   78  ansible-galaxy role
   81  ansible-galaxy role init web
  119  ansible-galaxy role install geerlingguy.java
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

34 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Ville Kääriä
Ville Kääriä
5 months ago

What is Ansible?
Configuration managent tool developed by Red Hat

Why Ansible?
– Agentless
– Desired state
– Works as documentation how server has been configured
– Lots of built in modules to do most configuration fast and with safety checks
– Playbooks are YAML so they are easy to read and edit
– Written with python. Python is very popular language so Ansible is relatively easy to extend with custom functionality

Ansible Architecture?
Human -> ACS -> ARS
ACS ansible control server
ARS ansible remote server

What is module?
Usually written in python but can be in any language -> resides in ACS -> run in ARC
— Reusable code that ansible runs on target machine, can be local or remote machine

What is Plugins?
Python -> resides in ACS -> run in ACS
— Extends core ansible funtionality

Zbigniew Zysiak
Zbigniew Zysiak
5 months ago

Ansible is a configuration management tool with possibility to access mulpliple endpoints on multiple OS platforms with many functionable modules and plugins which expand it’s functionality. It contain functionality to create “playbooks” what make it also great solution for automatization.

Why Ansible?
Cross platform / agentless solution which allow to reach configuration and build automatization.

Ansible Architecture?
Main tool server with optional relays which allow to communicate with endpoints using domain/local credentials managed also in Ansible.

What is module?
Module is a piece of code which allow to expand functionaly which can be performed on endpoint servers.

What is Plugins?
Module is a piece of code which allow to expand functionaly of Ansible server – functions used localy on Ansible server.

Jacek Szałęga
Jacek Szałęga
5 months ago

## What is Ansible?
Ansible is an open-source IT automation tool created by redhat, that automates tasks such as provisioning, configuration management, application deployment

## Why Ansible?
Ansible is simple, easy to use,it can help set up environments, ensure that correct prerequisites are installed and configured

## What is the Ansible Architecture?
Ansible architecture consists of a control node (Ansible Controller Server) and managed nodes(Ansible Remote Server). The control node is where Ansible is executed from, and managed nodes are the devices being automated. Ansible works by connecting to managed nodes and pushing out small programs, called “Ansible modules”

## What is module?
Modules in Ansible are units of code that control system resources or execute system commands. They can be used directly on remote hosts or through playbooks or adhoc commands

## What are the Plugins?
Plugins in Ansible are pieces of code that extend its core functionality.

shardendu
shardendu
5 months ago

What is Ansible?

Ansible is agentless configuration managment tool for executing tasks running scripts , instllation of softwares etc on managed nodes (ARS)

Why Ansible?

Ansible can be used on mulitple OS platoforms and with no agents installed on ARS

Ansible Architecture?

Ansible has simple control node ( installed ansible on this node – ARC) and managed nodes (ARS) where tasks are carreied out

What is module?

In Ansible, a module is like a little script that does a specific job. You can use these modules to perform tasks like copying files, installing software, or restarting a server (ARC)

What is Plugins?

Plugins in Ansible are like extra tools or add ons that can be used for extending functionalities (ARC)

Kostiantyn Konstantinov
Kostiantyn Konstantinov
5 months ago

## What is Ansible?
Ansible is configuration management tool used as an automation system.
## Why Ansible?
Ansible can handle all platforms, is easy to manage, and many plugins and modules are available to make automation easier.
## Ansible Architecture?
Ansible consists of executables, modules, plugins, config files.
## What is module?
Module is a python code of some action that we want to perform on a target system.
## What is Plugins?
Plain is a python code that add functionality to the Ansible server.

swati singh
swati singh
5 months ago

What is Ansible?
-automation tool to automate repetitive tasks of managing/configuring remote systems, which makes admin tasks easy.

Why Ansible?
-to automate repetitive tasks. Centrally manage/configure systems.

Ansible Architecture?
-ACS (Ansible control system)
-ARS (Ansible remote system)

What is module?
-re-usable Piece of code that performs specific task. no need to write code from scratch for which module exists.

What is Plugins?
-plugins enhances functionality of ansible, used by ACS. They act like features in ansible. There are some default plugins ,pre-package with installation, some can be downloaded and used as required.

Victor Palomo
Victor Palomo
5 months ago

What is Ansible?

It’a tool that automate all kind of frecuent task in all operating systems

Why Ansible?

Save time to perform repetitive tasks with several servers and operating systems.

Ansible Architecture?

Master server —–host inventory ——Plugins—–> modules ——> client hosts —–> Action

What is module?

Code that execute some tasks

What is Plugins?

Group of modules to perform an automation task.

Faisal
Faisal
5 months ago

1.A. Ansible is tool that helps to manage multiple servers, their configuration and deployment of application functionality.

2.A. Ansible can be used to manage, configure and deploy codes across different platforms.

3.A. We have ACS (Ansible Command Server) which controls the execution and Ansible installed and then we have ARS (Ansible Remote Servers) endpoint where the configuration and deployments needs to be deployed.

4.A. Modules are the predefined codes on Ansible server which required arguments to be passed to complete the tasks defined within modules

5.A. Plugins reside with in the command server and are used to support core functionality of transforming data, logging output and connecting to inventory. We have predefined plugins that gets installed as part of installation and can further be added through external sources as well.

Luis trabattoni
Luis trabattoni
5 months ago

Ansible is an open source community project sponsored by Red Hat, it’s the simplest way to automate IT. 
Ansible lets you quickly and easily deploy multitier apps. You won’t need to write custom code to automate your systems; you list the tasks required to be done by writing a playbook, and Ansible will figure out how to get your systems to the state you want them to be in.
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 modules are units of code that can control system resources or execute system commands. Ansible provides a module library that you can execute directly on remote hosts or through playbooks. You can also write custom modules.
Plugins are pieces of code that augment Ansible’s core functionality. Ansible uses a plugin architecture to enable a rich, flexible and expandable feature set. Ansible ships with a number of handy plugins, and you can easily write your own.

Kiran Kumar Vuyyuru
Kiran Kumar Vuyyuru
5 months ago

What is Ansible ?
 
Ansible is a command-line automation software application written in Python. It can configure systems, deploy software, and orchestrate advanced workflows to support application deployment, system updates, and more.
 
 
Why Ansible?
 
Ansible’s is simple and ease of use.
Ansible lets you quickly and easily deploy multitier apps. You won’t need to write custom code to automate your systems.

Ansible Architecture?InventoryModulesPlugin’sAPIWhat is module ?
A module is a reusable, standalone script that Ansible runs on your behalf, either locally or remotely
 

What is Plugins?  
 plugins allow Ansible to connect to the target hosts so it can execute tasks on them. 

Silvia Acosta Oleta
Silvia Acosta Oleta
5 months ago

What is Ansible?
Is a configuration management tool, easy of use, multiples servers  
Why Ansible?
you can deploy multiple apps, Not required to write custom code to automate your the systems
Ansible Architecture?
Human, ACS, ARS, You only connect via SSH for Linux or Winrm for windows
What is module?
are units of code that allow us control system resources or 
execute system commands. 

What is Plugins?
Are pieces of code that augment Ansible’s core functionality.
reside and run in ACS 

Milan Schild
Milan Schild
5 months ago

What is Ansible?
Platform for config automation tool

Why Ansible?
universal for linux/win, one cfg place many target servers, wide support by redhat

Ansible Architecture?
modules, plugins, inventory

What is module?
module is a piece of code which is executed on target systems as a separate process

What is Plugins?
plugin is also a piece of code, but it’s launched as a part of ansible process

Mariano Gazzola
Mariano Gazzola
5 months ago

>What is Ansible?
A configuration tool
>Why Ansible?
Let’s u quickly deploy, config, administer distributed applications in an automated manner, help to eliminate toil, prevents human error
>Ansible Architecture?
Human operator —> ACS –> ARSs
ARS are the target systems, also the inventory of administered servers
ACS is the computer where you have ansible installerd, with modules, plugins and playbooks.
>What is module?
Code libraries already made coming with Ansible or third part made, for controlling target system resources
>What is Plugins?
Code libraries that extend the functionality of ansible

Dirk Willemans
Dirk Willemans
5 months ago

What is Ansible?
Ansible is a tool that provides simple but powerful automation cross-platform.

Why Ansible?
You can use it cross-platform , you can setup or configure almost any device which you can connect to with ssh. Also windows via winrm. Also network switches , storage devices, …. You can start small en end up managing a whole infra. You can use it everywhere also at home. YOu can use it for infra as a code -> devops
No agent needed, on,ly abel to connect to your end-point

Ansible Architecture?
You have a acs and a ars. You run ansible playbooks from acs and execute on ARS.
You need to have an inventory.
You can use modules and plugins.

What is module?is code (python, powershell, ruby) that you execute on ARS
ansible copies the code to ARS, executes and removes the code after execution.

What is Plugins?are executing on the ACS. Plugins are offering extra functionality on the ACS:

  • tranform data
  • logging output
  • connecting to an inventory
Francisco Jose Montoya
Francisco Jose Montoya
5 months ago

What is Ansible?

Ansible is a configuration tool that help us to manage multiple servers with different OS using a common lenguage and it’s supported by a very large community

Why Ansible?
Because use a common “programing” lenguage to work with multiple servers, its idempotent so your changes will only be apply if the are something to be done, if not, it will not do anything
and with the community help there are more functionalities added for our benefit

Ansible Architecture?
Ansible uses a Control-remotes architecture, so you should only be writing you changes in one place and be distributed to the remotes using different lenguages according to their requirements.

What is module?

A module is a code write in the control server that runs in the remote servers and it’s used to used to do some activities on the remote hosts

What is Plugins?
It’s a code write in the control servers that runs in the same control server and help us to expand the Ansible capabilities

Arturo Alvarado Esparza
Arturo Alvarado Esparza
5 months ago

What is Ansible?
Ansible is a configuration management tool that automates storage, servers and networking. Is an open source, command line IT automation software written in python

Why Ansible?
Because it helps for automation, configuration and management of IT infraestructure. It works in Windows and Linux SO. It was designed to increase automation accesibility to reduce repetitive task. It’s easy to learn and self-documenting

Ansible Architecture?
Ansible follows a client-server arquitecture, where the server (ACS Ansible control server) communicates with multiple clients (ansible remote servers- managed nides) to execute task. Annsible control acts as the central point of control an can be installed on any Linux

What is module?
Ansible modules are units of code that can control system resources or execute system commands. Ansible works by connecting to servers and execute these modules. Modules accepts parameters.

What is Plugins?
Ansible are pieces of code that argument Ansibles core funcionality

Adam
Adam
5 months ago

# What is Ansible?
Configuration management tool using idempotetnt configuration files / scripts in yaml where the desired status is defined.

# Why Ansible?
One of the major IT companies is behind it, RedHat, which helps it to be popular and improved.
Otherwise the playbooks have simple and easily readable syntax, you get lots of modules for popular OSes ( and other software ), but for example not for AIX.

# Ansible Architecture?
The engine runs on the controller node from which you push the playbook to the clients where its been interpreted by python.

# What is module?
Modules are small programs that implements a feature for example handling packages for package management. These are then interpreted on the clients into actions.

# What is Plugins?
Plugins are extenstions for the ansible engine which implements additional features, like the become plugin which helps privilege elevation.

Vijay Pathania
Vijay Pathania
5 months ago

What is Ansible?
Ansible is configuration management tool.
It provides automation for cross-platform.
Why Ansible?
It is agentless and its simplicity because the code can be written in yml which is easier for humans to read and understand than other difficult coding languages.
There are lots of modules in ansible which makes job easier.

Ansible Architecture?

We have Ansible controller node and we have server and we have nodes.
Modules
Plugins
Inventory
PLaybooks
Config file
What is module?
It is something which reside in ACS and runs on ARS.
It is a code which can control system resources or execute system commands.

What is Plugins?
It is something which reside in ACS and runs in ACS
It offers options and extensions for the core features of ansible like
transforming data, logging output, connecting to inventory etc.

Daniel F Hernandez
Daniel F Hernandez
5 months ago

# What is Ansible?
Is a cross-platform automation tool.

# Why Ansible?
You can reach multiple nodes with different platforms at once. Wherever they are on-premise enviroment or in cloud environment. And automate several tasks.

# Ansible Architecture?
Users
Ansible Configuration Host
Ansible Remote Hosts

# What is module?
Is a logical container for ansible playbooks

# What is Plugins?
Are pieces of code that handles arguments or parameters for its functionality

Sammi
Sammi
5 months ago

#What is Ansible?
It’s config management tool, which we can use automate operations tasks.
Provided by redhat.

#Why Ansible?
Use one way to implement automation across different environment.
Easy to create, update, run, manage the automation script and verify result through web UI.

#Ansible Architecture?
Ansible consists of following components:
1. Control Node: Ansible platform control center. Containes all component files.
2. Inventory: Contains managed nodes settings. Ansible use SSH/WinRM tp communicated with nodes.
3. Playbook: Yaml files to define actions or commands of tasks.
4. Modules: Program or scripts which can be executed on specify nodes.
5. Plugins: To integrate with other systems.

#What is module?
It can be a program or script which can be executed on specify nodes to perform the tasks we need.

#What is Plugins?
Provide functions to integrate with other systems. such as email, logging, alert system.

Linus Shen
Linus Shen
5 months ago

What is Ansible? A: A tool to do automation and manage your automation job
Why Ansible? A: Just a tool, maybe you can choose argocd or jenkins
Ansible Architecture? A: app with postgresql
What is module? A: you can coding some functions to use , in ansible that call module
What is Plugins? A: Plungins extend Ansible’s core functionality. Most plugin types execute on the control node within the /usr/bin/ansible

Ville Kääriä
Ville Kääriä
5 months ago

Program 1 – Write a Ansible Adhoc Commands to create a group called “deploy
ansible localhost -b -m group -a “name=deploy”

Program 2 – Write a Ansible Adhoc Commands to create a user called “deploy-user” which is part of group called “deploy” and with /bin/bash shell.
ansible localhost -b -m user -a “name=deploy-user group=deploy shell=/bin/bash”

Program 3 – Write a Ansible Adhoc commands install package named “httpd” in RHEL/centos.
ansible localhost -b -m apt -a “name=apache2”

Program 4 – Write a Ansible Adhoc commands to start and enable the service named “httpd”
ansible localhost -b -m service -a “name=apache2 state=started enabled=yes”

Program 5 – Write a Ansible commands to create a file called “index.html” in /var/www/html with some dummy html contents.
ansible localhost -b -m copy -a “dest=/var/www/html/index.html content=’Dummy content'”

Program 6 – Write a Ansible commands to copy a file called “second.html” in /var/www/html/second.html with some dummy html contents.
ansible localhost -b -m copy -a “src=second.html dest=/var/www/html/second.html”

Program 7 – Write a Ansible commands to install a package called “git”, “wget”.
ansible localhost -b -m apt -a “name=git,wget”

Program 8 – Write a Ansible Adhoc commands to clone git repo. https://github.com/scmgalaxy/ansible-role-template.
ansible localhost -b -m git -a “repo=https://github.com/scmgalaxy/ansible-role-template dest=/tmp/ansible-role-template”

Program 9 – Write a Ansible commands to reboot a self machine.
ansible localhost -b -m reboot

Program 10 – Write a Ansible commands to touch a file called “devopsschool.txt” in /opt/ and delete after using ansible adhoc command.
ansible localhost -b -m file -a “state=touch path=/opt/devopsschool.txt”
ansible localhost -b -m file -a “state=absent path=/opt/devopsschool.txt”

Dirk Willemans
Dirk Willemans
5 months ago

Program 1 – Write a Ansible Adhoc Commands to create a group called “deploy”
ansible localhost -m group -a”state=present name=deploy”
Program 2 – Write a Ansible Adhoc Commands to create a user called “deploy-user” which is part of group called “deploy” and with /bin/bash shell.
ansible localhost -m user -a”state=present name=deploy-user group=deploy shell=/bin/bash”
Program 3 – Write a Ansible Adhoc commands install package named “httpd” in RHEL/centos.
ansible localhost -m yum -a”state=present name=httpd”
Program 4 – Write a Ansible Adhoc commands to start and enable the service named “httpd”
ansible localhost -m service -a”state=started enabled=true name=httpd”
Program 5 – Write a Ansible commands to create a file called “index.html” in /var/www/html with some dummy html contents.
ansible localhost -m copy -a”dest=/var/www/html/index.html content=’hello world'”
Program 6 – Write a Ansible commands to copy a file called “second.html” in /var/www/html/second.html with some dummy html contents.
ansible localhost -m copy -a”src=second.html dest=/var/www/html/second.html”
Program 7 – Write a Ansible commands to install a package called “git”, “wget”.
ansible localhost -m yum -a”state=present name=git,wget”
Program 8 – Write a Ansible Adhoc commands to clone git repo. https://github.com/scmgalaxy/ansible-role-template.
ansible localhost -m git -a”repo=https://github.com/scmgalaxy/ansible-role-template dest=git/ansible-role-template”
Program 9 – Write a Ansible commands to reboot a self machine.
ansible localhost -m reboot
Program 10 – Write a Ansible commands to touch a file called “devopsschool.txt” in /opt/ and delete after using ansible adhoc command.
ansible localhost -m file -a’state=touch path=/opt/dw.testfile’
ansible localhost -m file -a’state=absent path=/opt/dw.testfile’

Bert Smets
Bert Smets
5 months ago

What is Ansible?
A configuration management tools for servers.

Why Ansible?
To have a tools that uses 1 “language” for all platforms, easy to learn and manage.

Ansible Architecture?
Ansible has an architecture that consists of two types of nodes: a control node and one or more managed nodes. The control node is where Ansible is installed and run, and the managed nodes are the devices or systems that are configured and managed by Ansible.

What is module?
A piece of code, usually (but not mandatory) written in Python that can be used to execute certain action on the ARS (Ansible remote server). The module itself is located on the ACS (ansible controller server).

What is Plugins?
A piece of code that resides in the ACS and runs on the ACS. Plugins are pieces of code that augment Ansible’s core functionality.

Program 1 – Write a Ansible Adhoc Commands to create a group called “deploy
ansible web,db -i inventory -m group -a”name=deploy” -u ubuntu -k -b

Program 2 – Write a Ansible Adhoc Commands to create a user called “deploy-user” which is part of group called “deploy” and with /bin/bash shell.
ansible web,db -i inventory -m user -a”name=deploy-user group=deploy shell=/bin/bash” -u ubuntu –key node.pem -b

Program 3 – Write a Ansible Adhoc commands install package named “apache2” in Ubuntu.
ansible web -i inventory -m apt -a”state=latest name=apache2″ -u ubuntu –key-file=node.pem -b

Program 4 – Write a Ansible Adhoc commands to start and enable the service named “apache2”
ansible localhost -m service -a”name=apache2 state=started” 

Program 5 – Write a Ansible commands to create a file called “index.html” in /var/www/html with some dummy html contents.
ansible localhost -m file -a”path=”/var/www/html/index.html” state=touch”

Program 6 – Write a Ansible commands to copy a file called “second.html” in /var/www/html/second.html with some dummy html contents.
ansible localhost -m copy -a”src=”second.html” dest=”/var/www/html/second.html”

Program 7 – Write a Ansible commands to install a package called “git”, “wget”.
ansible localhost -m apt -a”state=latest name=git,wget”

Program 8 – Write a Ansible Adhoc commands to clone git repo. https://github.com/scmgalaxy/ansible-role-template.
ansible localhost -m git -a”clone=true dest=/home/ubuntu/bert/repo repo=https://github.com/scmgalaxy/ansible-role-template”

Program 9 – Write a Ansible commands to reboot a self machine.
ansible localhost -m reboot -a “msg=’Reboot triggered by Ansible'”

Program 10 – Write a Ansible commands to touch a file called “devopsschool.txt” in /opt/ and delete after using ansible adhoc command.
ansible localhost -m file -a”path=”/opt/devopsschool.txt” state=touch”
ansible localhost -m file -a”path=”/opt/devopsschool.txt” state=absent”

Danny Rubiano
Danny Rubiano
5 months ago

What is Ansible?
Ansible is an open-source IT automation tool that automates tasks such as software provisioning, configuration management, and deployment. Ansible is agentless, meaning that it does not require any software to be installed on the remote hosts that it manages. This makes Ansible easy to set up and use, and it can be used to manage a wide variety of systems, including Linux, Windows, and macOS.
Why Ansible?
There are many reasons to choose Ansible for IT automation, including:

  • Easy to use: Ansible is a very user-friendly tool, even for those who are new to IT automation.
  • Agentless: Ansible does not require any software to be installed on the remote hosts that it manages.
  • Powerful: Ansible can be used to automate a wide variety of tasks, from simple software provisioning to complex configuration management.
  • Flexible: Ansible can be used to manage a wide variety of systems, including Linux, Windows, and macOS.
  • Scalable: Ansible can be used to manage large numbers of systems without requiring any additional infrastructure.

Ansible Architecture
Ansible has a simple architecture that consists of two main components:

  • Control node: The control node is the machine that runs Ansible and from which Ansible commands are issued.
  • Managed nodes: Managed nodes are the remote hosts that Ansible manages.

Ansible uses SSH to connect to the managed nodes and execute tasks. Ansible modules are executed on the managed nodes, and they can be used to perform a wide variety of tasks, such as installing software, configuring services, and managing files.
What is a module?
An Ansible module is a Python script that performs a specific task on a managed node. Modules are the building blocks of Ansible playbooks, which are scripts that automate complex tasks by executing multiple modules in sequence.
There are hundreds of built-in Ansible modules, and many more are available from third-party sources. Modules can be used to perform a wide variety of tasks, such as:

  • Managing packages
  • Configuring services
  • Managing files
  • Executing commands
  • Gathering information

What are plugins?
An Ansible plugin is a piece of code that extends Ansible’s core functionality. There are many different types of plugins, including:

  • Connection plugins: Connection plugins allow Ansible to connect to different types of systems, such as Linux, Windows, and macOS.
  • Action plugins: Action plugins allow Ansible to perform additional tasks, such as restarting services and sending notifications.
  • Lookup plugins: Lookup plugins allow Ansible to retrieve data from external sources, such as databases and APIs.
  • Filter plugins: Filter plugins allow Ansible to manipulate data.

Plugins can be used to extend Ansible in a variety of ways, and they can make Ansible even more powerful and flexible.

Adam
Adam
5 months ago

## below become method works if the ansible user is logging in with ssh key and sudo is configured with NOPASSWD on the remote node

Program 1 – Write a Ansible Adhoc Commands to create a group called “deploy

# ansible <hostname> -i <inventory file> -m group -a “name=deploy state=present” -b

How to verify?
$ more /etc/group | grep deploy

Program 2 – Write a Ansible Adhoc Commands to create a user called “deploy-user” which is part of group called “deploy” and with /bin/bash shell.

# ansible <hostname> -i <inventory file> -m user -a “name=deploy-user group=deploy state=present shell=/bin/bash” -b

How to verify?
$ more /etc/passwd | grep deploy-user

Program 3 – Write a Ansible Adhoc commands install package named “httpd” in RHEL/centos.

# ansible <hostname> -i <inventory file> -m dnf -a “name=httpd state=latest” -b

How to verify?
$ which httpd

Program 4 – Write a Ansible Adhoc commands to start and enable the service named “httpd”

# ansible <hostname> -i <inventory file> -m service -a “name=httpd state=started enabled=true” -b

How to verify?
$ ps -eaf | grep httpd

Program 5 – Write a Ansible commands to create a file called “index.html” in /var/www/html with some dummy html contents.

# ansible <hostname> -i <inventory_file> -m copy -a “dest=/var/www/html/index.html content=’some dummy html contents'” -b

How to verify?
Browse http://x.x.x.x:80

Program 6 – Write a Ansible commands to copy a file called “second.html” in /var/www/html/second.html with some dummy html contents.

# ansible <hostname> -i <inventory_file> -m copy -a “dest=/var/www/html/second.html content=’some dummy html contents'” -b

How to verify?
Browse http://x.x.x.x/second.html

Program 7 – Write a Ansible commands to install a package called “git”, “wget”.

# ansible <hostname> -i <inventory_file> -m dnf -a “name=git,wget state=latest” -b

How to verify?
$ which git
$ which wget

Program 8 – Write a Ansible Adhoc commands to clone git repo. https://github.com/scmgalaxy/ansible-role-template.

# ansible <hostname> -i <inventory_file> -m git -a “name=https://github.com/scmgalaxy/ansible-role-template dest=<dest_dir>”

How to verify?
$ ls

Program 9 – Write a Ansible commands to reboot a self machine.

# ansible <hostname> -i <inventory_file> -m reboot -b

Program 10 – Write a Ansible commands to touch a file called “devopsschool.txt” in /opt/ and delete after using ansible adhoc command.

# ansible <hostname> -i <inventory_file> -m file -a “name=/opt/devopsschool.txt state=touch” -b
# ansible <hostname> -i <inventory_file> -m file -a “name=/opt/devopsschool.txt state=absent” -b

Francisco Jose Montoya
Francisco Jose Montoya
5 months ago

Program 1 – Write a Ansible Adhoc Commands to create a group called “deploy
ansible all -i inventory -m group -a”name=deploy state=present” -u ubuntu –key-file=node.pem -b

How to verify?
$ more /etc/group | grep deploy
ansible all -i inventory -a”grep deploy /etc/group” -u ubuntu –key-file=node.pem -b

Program 2 – Write a Ansible Adhoc Commands to create a user called “deploy-user” which is part of group called “deploy” and with /bin/bash shell.

ansible all -i inventory -m user -a”name=deploy-user groups=deploy” -u ubuntu –key-file=node.pem -b

How to verify?
$ more /etc/passwd | grep deploy-user

ansible all -i inventory -a”grep deploy-user /etc/passwd” -u ubuntu –key-file=node.pem -b

Program 3 – Write a Ansible Adhoc commands install package named “httpd” in RHEL/centos.
ansible all -i inventory -m apt -a”state=latest name=httpd” -u ubuntu –key-file=node.pem -b

How to verify?
$ which httpd
ansible all -i inventory -a”which httpd” -u ubuntu –key-file=node.pem -b

Program 4 – Write a Ansible Adhoc commands to start and enable the service named “httpd”
ansible all -i inventory -m service -a”name=httpd state=started” -u ubuntu –key-file=node.pem -b

How to verify?
$ ps -eaf | grep httpd
ansible localhost -m shell -a”ps -fea | grep httpd” -u ubuntu –key-file=node.pem -b

Program 5 – Write a Ansible commands to create a file called “index.html” in /var/www/html with some dummy html contents.
ansible all -i inventory -m copy -a’content=”<h1> Hello World – Fran </h1>” dest=/var/www/html’ -u ubuntu –key-file=node.pem -b

How to verify?
Browse http://x.x.x.x:80

Program 6 – Write a Ansible commands to copy a file called “second.html” in /var/www/html/second.html with some dummy html contents.
ansible all -i inventory -m copy -a”src=second.html dest=/var/www/html/second.html” -u ubuntu –key-file=node.pem -b

How to verify?
Browse http://x.x.x.x/second.html

Program 7 – Write a Ansible commands to install a package called “git”, “wget”.
ansible all -i inventory -m apt -a”state=latest name=git,wget” -u ubuntu –key-file=node.pem -b

How to verify?
$ which git
$ which wget
ansible all -i inventory -a”which git” -u ubuntu –key-file=node.pem -b
ansible all -i inventory -a”which wget” -u ubuntu –key-file=node.pem -b

Program 8 – Write a Ansible Adhoc commands to clone git repo. https://github.com/scmgalaxy/ansible-role-template.
ansible all -i inventory -m git -a”repo=’https://github.com/scmgalaxy/ansible-role-template’ dest=/home/ubuntu/ansible-role-template” -u ubuntu –key-file=node.pem -b

How to verify?
$ ls
ansible all -i inventory -a”ls /home/ubuntu/” -u ubuntu –key-file=node.pem -b

Program 9 – Write a Ansible commands to reboot a self machine.
ansible all -i inventory -m reboot -a”reboot_timeout: 3600″ -u ubuntu –key-file=node.pem -b

Program 10 – Write a Ansible commands to touch a file called “devopsschool.txt” in /opt/ and delete after using ansible adhoc command.
ansible all -i inventory -m copy -a’content=”” dest=/opt/devopsschool.txt owner=root” -u ubuntu –key-file=node.pem -b
ansible all -i inventory -m file -a’path=/opt/devopsschool.txt state:absent” -u ubuntu –key-file=node.pem -b

Ankur Malik
Ankur Malik
5 months ago

What is Ansible?
Ansible is configuration management tool, can say that It’s enables infrastructure as code. Also Ansible is agentless, relying on temporary remote connections via SSH or Windows Remote Management which allows PowerShell execution.

Why Ansible?
Ansible can be used for a variety of purposes, but it’s most commonly used to automate the deployment and configuration of systems such as servers, virtual machines, and applications. It can be used to perform tasks such as installing software packages, configuring networking settings, and updating system configurations.

Ansible Architecture?

Ansible Architecture:-
– ACS and ARS
– Modules
– Plugins
– Inventory
– Playbooks

What is module?
Ansible works by connecting to your nodes and pushing out small programs, called “Ansible Modules” to them. These programs are written to be resource models of the desired state of the system. Ansible then executes these modules over SSH by default, and removes them when finished.

What is Plugins?

Plugins are pieces of code that augment Ansible’s core functionality. Ansible ships with a number of handy plugins, and that can be easily write.

Alison Silva
Alison Silva
5 months ago

What is Ansible?
Open code IT automation tool

Why Ansible?
Open source, use yaml that is very common nowadays, agentless.

Ansible Architecture?
control nodes and managed nodes

What is module?
Its like a program that are used to execute tasks.
Code that can control system resources or execute system commands

What is Plugins?
pieces of code that augment Ansible’s core functionality

Dirk Willemans
Dirk Willemans
5 months ago


– hosts: localhost
 gather_facts: false
 tasks:
  – name: ‘1. create group’
   group:
    name: deploy
    state: present
  – name: ‘2. create user’
   user:
    name: deploy-user
    state: present
    groups: deploy
    shell: /bin/bash
  – name: ‘3. install package’
   yum:
    name: httpd
    state: present
  – name: ‘4. start and enable service httpd’
   service:
    name: httpd
    state: started
    enabled: true
  – name: ‘5. create file’
   copy:
    dest: /var/www/html/index.html
    content: |
     hello world !!!
  – name: ‘7. install packages’
   vars:
    packages:
     – git
     – wget
   yum:
    name: “{{ packages }}”
    state: present
  – name: ‘8. git clone repo’
   git:
    repo: https://github.com/scmgalaxy/ansible-role-template
    dest: git/https://github.com/scmgalaxy/ansible-role-template

Ville Kääriä
Ville Kääriä
5 months ago


hosts: localhost
  become: true
  tasks:
  – name: Write a Ansible Playbook to create a group called deploy
    group:
      name: deploy
  – name: Write a Ansible Playbook to create a user called deploy-user which is part of group called deploy and with /bin/bash shell.
    user:
      name: deploy-user
      group: deploy
      shell: /bin/bash
  – name: Write a Ansible Playbook to install package named apache2 in Debian/Ubuntu.
    package:
      name: apache2
      state: present
  – name: Write a Ansible Playbook to start and enable the service named apache2
    service:
      name: apache2
      state: started
      enabled: yes
  – name: Write a Ansible Playbook to create a file called index.html in /var/www/html with some dummy html contents.
    copy:
      content: ‘<h1>Dummy content</h1>’
      dest: /var/www/html/index.html
  # – name: Write a Ansible Playbook to reboot a self machine.
  #   reboot:
  – name: Write a Ansible Playbook to install a package called git, wget.
    package:
      name:
        – git
        – wget
      state: present
  – name: Write a Ansible Playbook to clone git repo. https://github.com/scmgalaxy/ansible-role-template
    git:
      repo: ‘https://github.com/scmgalaxy/ansible-role-template’
      dest: /tmp/ansible-role-template

Danny Rubiano
Danny Rubiano
5 months ago

What is Ansible?
Ansible is an open-source IT automation tool that automates tasks such as software provisioning, configuration management, and deployment. Ansible is agentless, meaning that it does not require any software to be installed on the remote hosts that it manages. This makes Ansible easy to set up and use, and it can be used to manage a wide variety of systems, including Linux, Windows, and macOS.
Why Ansible?
There are many reasons to choose Ansible for IT automation, including:

  • Easy to use: Ansible is a very user-friendly tool, even for those who are new to IT automation.
  • Agentless: Ansible does not require any software to be installed on the remote hosts that it manages.
  • Powerful: Ansible can be used to automate a wide variety of tasks, from simple software provisioning to complex configuration management.
  • Flexible: Ansible can be used to manage a wide variety of systems, including Linux, Windows, and macOS.
  • Scalable: Ansible can be used to manage large numbers of systems without requiring any additional infrastructure.

Ansible Architecture
Ansible has a simple architecture that consists of two main components:

  • Control node: The control node is the machine that runs Ansible and from which Ansible commands are issued.
  • Managed nodes: Managed nodes are the remote hosts that Ansible manages.

Ansible uses SSH to connect to the managed nodes and execute tasks. Ansible modules are executed on the managed nodes, and they can be used to perform a wide variety of tasks, such as installing software, configuring services, and managing files.
What is a module?
An Ansible module is a Python script that performs a specific task on a managed node. Modules are the building blocks of Ansible playbooks, which are scripts that automate complex tasks by executing multiple modules in sequence.
There are hundreds of built-in Ansible modules, and many more are available from third-party sources. Modules can be used to perform a wide variety of tasks, such as:

  • Managing packages
  • Configuring services
  • Managing files
  • Executing commands
  • Gathering information

What are plugins?
An Ansible plugin is a piece of code that extends Ansible’s core functionality. There are many different types of plugins, including:

  • Connection plugins: Connection plugins allow Ansible to connect to different types of systems, such as Linux, Windows, and macOS.
  • Action plugins: Action plugins allow Ansible to perform additional tasks, such as restarting services and sending notifications.
  • Lookup plugins: Lookup plugins allow Ansible to retrieve data from external sources, such as databases and APIs.
  • Filter plugins: Filter plugins allow Ansible to manipulate data.

Plugins can be used to extend Ansible in a variety of ways, and they can make Ansible even more powerful and flexible.

Faisal
Faisal
5 months ago

1.A. ansible-playbook grp.yaml

——————-
– name: Ensure group deploy1 exists
 hosts: localhost

 tasks:
  – name: Ensure group deploy1 exists
   ansible.builtin.group:
    name: deploy1
    state: present

2.A. ansible-playbook usr.yaml

—————-
– name: Ensure user deploy1 exists
 hosts: localhost

 tasks:
  – name: Ensure user deploy1 exists
   ansible.builtin.user:
    name: deploy1
    comment: Test user
    uid: 1040
    group: deploy1

3.A.ansible-playbook pkg.yaml

—————
– name: updating package
 hosts: localhost

 tasks:
  – name: updating package
   ansible.builtin.package:
    name:
     – httpd
     – mariadb-server
    state: latest

4.A. ansible-playbook ser.yaml

—————–
– name: Restart service
 hosts: localhost

 tasks:
  – name: Restart service httpd, in all cases
   ansible.builtin.service:
    name: httpd

5.A. ansible-playbook file.yaml

———-
– name: create file
 hosts: localhost

 tasks:
  – name: Touch a file, using symbolic modes to set the permissions (equivalent to 0644)
   ansible.builtin.file:
   path: /etc/foo.conf
   state: touch
   mode: u=rw,g=r,o=r

Ankur Malik
Ankur Malik
5 months ago


– hosts: localhost

 tasks:
   – name: create a group
    group:
     state: present
     name: deploy

   – name: Install git, wget and httpd
    apt:
     name: “{{ package }}”
     state: present
    vars:
     package:
      – git
      – wget
      – apache2

   – name: start the service httpd and enable
    service:
      name: apache2
      state: started
      enabled: true

   – name: create a user – deploy
    user:
     name: deploy
     state: present
     shell: /bin/bash
     group: deploy

   – name: Template index.html
    template:
     src: apache2.j2
     dest: /var/www/html/index.html
    vars:
     portnumber: 8080

34
0
Would love your thoughts, please comment.x
()
x