Ansible Tutorial - Package Management | Ansible Module YUM | APT

ansible module, ansible ad-hoc command, ansible yum module, ansible apt module, ansible tutorial
tags: ansible ad-hoc command, ansible yum module, ansible apt module, working with ansible module 
Ansible Module : Yum

Package manager for rpm family to Installs, upgrade, downgrades, removes, and lists packages and groups

To help about yum module

ansible-doc yum

ansible module, ansible ad-hoc command, ansible yum module, ansible apt module

Practice of yum module

Check if package is installed & update it
ansible 172.17.20.98 -m yum -a "name=vsftpd state=latest"
Check if package is installed & don’t update it
ansible 172.17.20.98 -m yum -a "name=vsftpd state=present"
ansible module, ansible ad-hoc command, ansible yum module, ansible apt module

Check if package is at a specific version
ansible 172.17.20.98 -m yum -a "name=vsftpd-3.0.2 state=present"

Install package from particular repo
ansible 172.17.20.98 -m yum -a "name=vsftpd state=installed disablerepo=* enablerepo=epel"
Video Tutorial :


Search Package
ansible 172.17.20.98 -m yum -a "list=available" | grep squid

check installed package
ansible 172.17.20.98 -m yum -a "list=installed" | grep squid
remove package
ansible 172.17.20.98 -m yum -a "name=vsftpd state=absent"


All Module Option:

allow_downgrade
autoremove
bugfix
conf_file
disable_excludes
disable_gpg_check
disable_plugin
disablerepo
download_only
enable_plugin
enablerepo
exclude
installroot
list
name
releasever
security
skip_broken
state
update_cache
update_only
use_backend
validate_certs


Apt  - Module

Manages `apt' packages such like Ubuntu or Debian

Get help of apt module, just type below command

ansible-doc  apt


Practice of apt module

Update cache
ansible 172.17.20.98 -m apt -a "update_cache=yes"


Check if package is installed & update it
ansible 192.168.3.104 -m apt -a "name=vsftpd state=latest"


Check if package is at a specific version
ansible 172.17.20.98 -m apt -a "name=vsftpd-3.0.2 state=present"
All Module Option:

allow_unauthenticated
autoclean
autoremove
cache_valid_time
deb
default_release
dpkg_options
force
force_apt_get
install_recommends
name
only_upgrade
purge
state
update_cache
upgrade




Thanks

End of this ansble tutorial- ansible systemd module and ansible service module, we need your support so i request you to please comment, share and like this post


www.linuxtopic.com



Ansible Tutorial - Service Management Modules | Service Module | Systemd Module

T
 ansible service  module, ansible systemd module with example and start service, stop service and restart service using ansible ad-hoc command.  ansible module, ansible ad-hoc command, ansible service module, ansible systemd module, andible, ansible command,
ags: ansible module, ansible ad-hoc command, ansible service module, ansible systemd module, andible, ansible command, 
[A] Ansible Module : Service


Controls services on remote hosts. Supported init systems include BSD, init, OpenRC, SysV, Solaris SMF, systemd, upstart. For Windows targets, use the [win_service] module instead.

To help service module
ansible-doc service
 ansible service  module, ansible systemd module with example and start service, stop service and restart service using ansible ad-hoc command.  ansible module, ansible ad-hoc command, ansible service module, ansible systemd module, andible, ansible command,


Check Service status
ansible 172.17.20.98 -m service -a "name=vsftpd" | grep ActiveState


Start service
ansible 172.17.20.98 -m service -a "name=vsftpd state=started"


Stop service
ansible 172.17.20.98 -m service -a "name=vsftpd state=stopped"


Restart Service
ansible 172.17.20.98 -m service -a "name=vsftpd state=restarted"


Enable service
ansible 172.17.20.98 -m service -a "name=vsftpd enabled=yes"


Disable service
ansible 172.17.20.98 -m service -a "name=vsftpd enabled=no"



Module Options :

arguments

enabled

pattern

runlevel

sleep

state

use



[B] Ansible Module :  systemd

Controls systemd services on remote hosts.

To help of systemd module
ansible-doc systemd


Check Service status
ansible 172.17.20.98 -m systemd -a "name=vsftpd" | grep ActiveState


Start service
ansible 172.17.20.98 -m systemd -a "name=vsftpd state=started"


Stop service
ansible 172.17.20.98 -m systemd -a "name=vsftpd state=stopped"


Restart Service
ansible 172.17.20.98 -m systemd -a "name=vsftpd state=restarted"


Enable service
ansible 172.17.20.98 -m systemd -a "name=vsftpd enabled=yes"


Disable service
ansible 172.17.20.98 -m systemd -a "name=vsftpd enabled=no"


Daemon Reload
ansible 172.17.20.98 -m systemd -a "daemon_reload=yes"


Restart, enable and daemon reload
ansible 172.17.20.98 -m systemd -a "name=vsftpd state=restarted daemon_reload=yes"




Module Options:


daemon_reload

enabled

force

masked

name

no_block

scope

state

user


Thanks

End of this ansible installation part in CentOS 7, we need your support so i request you to please comment, share and like this post


www.linuxtopic.com

Adding Remote Hosts in Ansible Inventory with Authenticate Using 3 Different Method - Ansible Tutorial


tags: devops tool ansible,devops,tools,ansible,tutorial,2019,ansible add remote hosts in inventory,add remote hosts,ansible remote host authentication method,automation tools,ansible_ssh_pass,ansible authentication using ssh key,ansible authentication with password,linuxtopic,linux topic,ansible hosts,ansible video turorial,ansible tower,ansible documentation,ansible family,ansble open source,
Ansible

OS - CentOS 7
Kernel - 3.10.0-693.17.1.el7.x86_64
IP - 172.17.20.100
Hostname - linuxtopic.com

Remote Nodes:

Node 1 :
UefiPXE  = 172.17.20.98
SSH Port = 22022
User = root

Node 2 : 
Ubuntu Server = 192.168.3.104 
SSH Port =  22
User = lokesh

Add remote hosts in inventory 

1) Password Authentication 
2) Preparing SSH Keys 
3) ssh-copy-id  


Video Tutorial in Hindi




1) Add remote hosts in inventory using Password  authentication 
vi /etc/ansible/hosts
[remote]
# Add host with password
192.168.3.104 ansible_ssh_user=lokesh ansible_ssh_pass=server32



To Ping Remote hosts group
ansible remote -m ping
ansible all -m ping


To check all configure hosts 
ansible --list-hosts all
To check groups hosts 
ansible --list-hosts remote


2) Authentication ansible hosts using ssh key 

Prepare ssh key in remote hosts, for example we have Ubuntu 16 with details:

Remote Host: 192.168.3.104
User: lokesh

To Install Openssh-server in Remote host 
apt install openssh-server


To generate ssh key using ssh-keygen 
ssh-keygenEnter passphrase ( emply for no passphrase) :Enter same passphrase again :


To verify ssh key file
cd .ssh/
cat id_rsa.pub 
To create authorized_keys file and copy public key 
cat id_rsa.pub >> /home/lokesh/.ssh/authorized_keys
cat id_rsa

Note: we require this private key ( id_rsa ) to authenticate with ansible 

Login in Ansible Server  and  create a key file with any suitable name and paste remote hosts Private key ( id_rsa )
vi /etc/ansible/remote-104.key
-----BEGIN RSA PRIVATE KEY-----

MIIEpAIBAAKCAQEArqw6AWoVPkebYQvlejJQPhJc/7tMVIrqnnhNtG2TbJ3DokaX

EalKkS2J6czexw6xqtl9sHQVA2guBEq51FQ/CX8RchdtQgInLb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o50MzXLUpRpvcBZ+hnMxtYvLqbEfnlews5

M8zObYO08fdPjGa3K2t1AQKBgQC9kuayPSxBRFbsSPFWA+dSvLovuJUKcumyE+3k

fZzpr6Vwb6mEj0A1bDz+A3y8UiPmYkkCRDQ754HT1hhGcqU1CNGGxybG6NL3dbv3

6wXRUjAbD1yO7uEZgtPSOqnw3+NemL/UF51i4buF5gy38506VOzpEtG1+fBSSsdT

DBGAaQKBgQCJN2kerW9+ecp08Bh79WwVdf8lyMjBwqx32thFu7f8c4heD4JZ/qJ/

WskapUzorqSNZpqr2ET/SdP0oZu0Z4ImH3MWxNVQeJd2TvpWfl45w/Ps+bVxwjju

3yGL1Gy7iku+7nocaNOG32ROB3Tu1l9NSPvmWmtRX6T0zV4x7NfIIw==

-----END RSA PRIVATE KEY-----


To set permission 
chmod 600 /etc/ansible/remote-104.key
To login  on remote host by ssh key
ssh -p22 -i /etc/ansible/remote-104.key [email protected]


Add remote host in inventory file using key file path
vi /etc/ansible/hosts
[localhost]
127.0.0.1

[remote]
192.168.3.104 ansible_ssh_user=lokesh ansible_ssh_private_key_file=/etc/ansible/remote-104.key



Verify hosts connectivity using ping module
ansible remote -m ping
ansible all -m ping



3) ssh-copy-id 

To copy ssh key using ssh-copy-id command
ssh-copy-id -p22 [email protected]
Type current password of lokesh user, it will auto copy the ssh key



Here: ssh-copy-id is command, -p22 is ssh port, lokesh is ssh user and 192.168.3.104 remote host 

Host 2: 
ssh-copy-id -p22022 [email protected]


Add Remote hosts in Inventory file
vi /etc/ansible/hosts
[localhost]
127.0.0.1

[remote]
192.168.3.104 ansible_ssh_user=lokesh ansible_become_pass=server32
172.17.20.98 ansible_port=22022



In inventory we use ansible_become_pass=server32, means we give sudo privileges 

To verify all hosts using ping ad-hoc command
ansible all -m ping


To check kernel version of all hosts using shell module 
ansible all -m shell -a "uname -a"