-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9eeab98
Showing
12 changed files
with
507 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
what is ansible? | ||
it is automation tool, whwre we can automate all repetitive process. | ||
|
||
Ansible Inventory: | ||
A list of managed nodes provided by one or more ‘inventory sources’. Your inventory can specify information specific to each node, like IP address. | ||
|
||
Ansible Playbooks: | ||
Ansible Playbooks are lists of tasks that automatically execute against hosts. | ||
|
||
Ansible Modules : | ||
various kind of command, which we can execute on rmemote system for desired output. | ||
ansible module which contain on -> docs.ansible.com | ||
|
||
Ansible Variables: | ||
variable is that may assume any one of a set of values, if you want to use file multiple time, then create a variable named as file, so whenever u want | ||
to use this file at that time u can give, variable name so it will get the data from variable property. | ||
|
||
Ansible Conditionals: | ||
we can give conditions, once it met condition, it will do the appropriate action on it. | ||
|
||
Ansible Loops : | ||
ansible can execute multiple times. example- 1 to 10 | ||
|
||
Ansible Roles: | ||
you can easily reuse them and share them with other users. | ||
|
||
how to find syntax for ansible? | ||
docs.ansible.com | ||
example for ansible automation? automatic turn on and turn off, configuraion, install apahe, patching..! | ||
|
||
use case of ansible: | ||
-------------------- | ||
provisoning | ||
configuration management | ||
continous delivery | ||
application deployment | ||
security compliance | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
doc refer: | ||
---------- | ||
https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html#installing-ansible-on-fedora-or-centos | ||
|
||
important | ||
---------- | ||
ansible only we can install linux based os, we cannot use anible on windows as master system, although we can manage windows | ||
instance. | ||
|
||
fedrora, centos, amazon linux, linux: | ||
-------------------------------------- | ||
install epel repo | ||
------------------ | ||
amazon linux:- amazon-linux-extras install install epel | ||
fedora, centos, rhel:- yum install epel | ||
|
||
install ansible | ||
--------------- | ||
yum install ansible |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
ansible_ssh_user(ansible_user) - username through ssh | ||
ansible_ssh_pass - passowrd through ssh | ||
ansible_private_key_file - private key file name | ||
ansible_user - username | ||
ansible_connection - ssh/winrm/localhost | ||
ansible_host - hostname | ||
ansible_port - which port want to connect | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
1) create pasword for remote system | ||
2) suppress host key checking:- | ||
goto ansible.cf file and search for host key checking and uncomment it | ||
3) with password authentication:- | ||
goto ansible host file add following line | ||
|
||
method one by using password: | ||
----------------------------- | ||
ip_address/hostname ansible_ssh_user=username ansible_ssh_pass=password | ||
|
||
command for check ping | ||
## ansible all -m ping | ||
|
||
method two by using ssh key: | ||
---------------------------- | ||
ip_address/hostname ansible_ssh_user=ec2-user ansible_private_key_file=key_destination | ||
|
||
command for check ping | ||
## ansible all -m ping | ||
|
||
method three by using password less authentication: | ||
--------------------------------------------------- | ||
ip_address/hostname ansible_ssh_user=username | ||
|
||
command for check ping | ||
## ansible all -m ping | ||
--------------------------------------------------------------------------------------------------------- | ||
how to create sepperate inventory file:- | ||
----------------------------------------- | ||
we can create sepperate inventory file as well..! | ||
|
||
create file "any_custom_name" example: targets | ||
|
||
use the same synatx (take any one): | ||
----------------------------------- | ||
ip_address/hostname ansible_ssh_user=ec2-user ansible_private_key_file=key_destination (password auth) | ||
ip_address/hostname ansible_ssh_user=username ansible_ssh_pass=password (ssh key auth) | ||
ip_address/hostname ansible_ssh_user=username (password less auth) | ||
|
||
try to ping with cited command: | ||
ansible groupname/target_name -m ping -i inventory_file_name | ||
|
||
ansible command | ||
---------------- | ||
ansible all/host -m ping | ||
ansible-playbook playbook_name | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
ansible use yaml to configure (yet another markup language) | ||
|
||
key/value pair: | ||
-------------- | ||
name: apple | ||
color: red | ||
place: kashmir | ||
(keep to leave small space in bewteen fullcoln and value) | ||
|
||
array/list: | ||
----------- | ||
fruits: | ||
- orange | ||
- apple | ||
- grapes | ||
|
||
veg: | ||
- tomato | ||
- carrot | ||
- cauliflower | ||
|
||
dictionary | ||
---------- | ||
banana: | ||
calory: 100g | ||
fat: 0.4g | ||
carbs: 27g | ||
|
||
grapes: | ||
calory: 120g | ||
fat: 0.6g | ||
carbs: 110g | ||
|
||
|
||
example; | ||
-------- | ||
fruits: | ||
- banana: | ||
calories: 105 | ||
fat: 0.4g | ||
carbs: 27g | ||
- grapes: | ||
calories: 105 | ||
fat: 0.4g | ||
carbs: 27g | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
to create dierctory | ||
------------------- | ||
to shutdown vm | ||
--------------- | ||
- name: this is ansible automation | ||
become: true | ||
hosts: all | ||
tasks: | ||
- name: shutdown hosts | ||
command: mkdir /mydir | ||
----------------------------------------------------------------------------------------------------- | ||
to shutdown vm | ||
--------------- | ||
- name: this is ansible automation | ||
become: true | ||
hosts: all | ||
tasks: | ||
- name: shutdown hosts | ||
command: /sbin/shutdown -h now | ||
---------------------------------------- | ||
- name: tets | ||
hosts: all | ||
become: yes | ||
tasks: | ||
- name: shutdown hosts | ||
command: /sbin/shutdown -h now | ||
--------------------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
module types | ||
------------ | ||
command | ||
-------- | ||
- command | ||
- expect | ||
- raw | ||
- script | ||
- shell | ||
|
||
database | ||
-------- | ||
- mongoDB | ||
- mssql | ||
- mysql | ||
- postgresql | ||
- proxysql | ||
- vertica | ||
|
||
windows | ||
------- | ||
- win_copy | ||
- win_command | ||
- win_file | ||
- win_msg | ||
- win_service | ||
system | ||
------- | ||
- user | ||
- group | ||
- hostname | ||
- iptables | ||
- lvg | ||
- lvol | ||
- make | ||
- mount | ||
- ping | ||
- timezone | ||
-systemd | ||
-service | ||
|
||
files | ||
------ | ||
- acl | ||
- archive | ||
- copy | ||
- file | ||
- find | ||
- lineinfile | ||
- replace | ||
- stat | ||
- template | ||
- unarchive | ||
|
||
cloud | ||
----- | ||
- amazon | ||
- azure | ||
- gcp | ||
- vmware | ||
- digital ocean | ||
|
||
more | ||
----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
refer- https://docs.ansible.com/ansible/2.5/modules/command_module.html#command-module | ||
create directory by using command/shell module: | ||
----------------------------------------- | ||
- name: automation | ||
hosts: all | ||
become: true | ||
tasks: | ||
- name: execute directory | ||
command: mkdir /home/newDir | ||
|
||
|
||
refer: https://docs.ansible.com/ansible/latest/collections/community/general/apache2_module_module.html | ||
-------------------------------------------------------------------------------- | ||
install webserver by using httpd module | ||
--------------------------------------- | ||
- name: installing apache by usign httpd | ||
hosts: all | ||
become: true | ||
tasks: | ||
- name: (httpd module) | ||
yum: | ||
name: httpd | ||
state: present | ||
- name: (service module) | ||
service: | ||
name: httpd | ||
state: present | ||
|
||
copy shell script from master to node by usign script module | ||
------------------------------------------------------------ | ||
- name: copy code from master to node | ||
hosts: all | ||
become: root | ||
tasks: | ||
- name: copy | ||
script: /file/path/script.sh | ||
|
||
[example-2] | ||
------------ | ||
- name: playbok for automate script | ||
hosts: all | ||
become: root | ||
tasks: | ||
- name: copy from master to node | ||
script: /etc/ansible/script.sh | ||
|
||
[shell script] | ||
-------------- | ||
#!/bin/bash | ||
sudo yum install httpd -y | ||
sudo systemctl start httpd.service | ||
sudo wget -P /var/www/html https://www.free-css.com/assets/files/free-css-templates/download/page284/pet-shop.zip | ||
sudo unzip -o /var/www/html/pet-shop.zip -d /var/www/html/ | ||
sudo cp -rf /var/www/html/pet-shop-website-template/* /var/www/html/ | ||
|
||
wget -P for purticulr directory | ||
unzip -o from overwrite | ||
unzip -d for save in purticular directory | ||
|
||
|
||
lineinfile module add a line in file | ||
------------------------------------ | ||
- name: installing apache by usign httpd | ||
hosts: all | ||
become: true | ||
tasks: | ||
- name: add line in resolv file | ||
lineinfile: | ||
path: /etc/resolv.conf | ||
line: nameserver 192.168.1.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
1 ansible [hostname] -m ping | ||
|
||
2 ansible-playbook play_book_name | ||
|
||
3 --check (not going to execute but i will give idea about plays, can understand the chnages in upcming script) | ||
|
||
4 -vvv , -vvvv (use for connection debugging) | ||
|
||
5 --version (to check version of ansible) | ||
|
||
6 --list-hosts (outputs a list of matching hosts; does not execute anything else) | ||
|
||
7 --syntax-check (to check syntax) | ||
|
||
8 --diff (not going to execute but i will give idea about plays, can understand the chnages in upcming script) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
variable | ||
-------- | ||
component of ansible, where we can store values and we can use with global scop. | ||
|
||
we can create sepparte 'variable file' or we can create 'vars' in inside playbook | ||
|
||
example: variable in same file | ||
- hosts: all | ||
name: play | ||
become: true | ||
vars: | ||
var1: var1 | ||
var2: reshma | ||
tasks: | ||
- name: first task | ||
lineinfile: | ||
path: /etc/resolv.conf | ||
line: '{{var1}}' | ||
|
||
------------------------------------------------------------------- | ||
mention variable in different file | ||
---------------------------------- | ||
create one more file var.yml | ||
|
||
goto playbook add path of 'vars_file: /etc/ansible/var.yml' | ||
|
||
- hosts: all | ||
name: play | ||
become: true | ||
vars_files: /etc/ansible/var.yml | ||
tasks: | ||
- name: first task | ||
lineinfile: | ||
path: /etc/resolv.conf | ||
line: '{{var1}}' |
Oops, something went wrong.