Ansible LAB
Ansible LAB
-----------------------------------------------------------------------
tasks:
- name: This is a task for useradd
user: name=prabhu uid=949 shell=/bin/bash state=present
playbook: firstplay.yml
[root@lansibletr-t4 ansible]#
[root@lansibletr-t4 ansible]# ansible-playbook firstplay.yml --check
PLAY RECAP
***********************************************************************************
*******************************************************
10.237.4.125 : ok=3 changed=0 unreachable=0 failed=0
[root@lansibletr-t4 ansible]#
===================================================================================
==
==============LAB Taksk
===================================================================
2- Create a directory /var/tmp/demo, create file with name demotest inside the
directory created, copy /var/log/messages on managed node
3- Stop NTPD and Install NTP again ,remove the all the contents from ntp.conf file
and only below lines
server0.rhel.pool.org srv0
server1.rhel.pool.org srv1
-----------------
---
- name: This is my first Ansible Playbook
hosts: 10.237.4.125
tasks:
-name: create group and user
group: name=India state=present
user: name=prabhu1 uid=2345 shell=/bin/bash groups=India
---
- name: This is my first Ansible Playbook
hosts: 10.237.4.125
tasks:
- name: create directory
file: path=/var/tmp/demo state=directory
- name: create file
file: name=demotest dest=/var/tmp/demo/ state=touch
- name: copy file from message to demotest file
copy: src=/var/log/messages dest=/var/tmp/demo/demotest
---
- name: This is my first Ansible Playbook
hosts: 10.237.4.125
tasks:
- name: This is a task for stop and remove ntp package
service: name=ntpd state=stopped enabled=no
package: name=ntp state=absent
- name: This is a task for Install ntp package
package: name=ntp state=present
- name: Configure the NTP configuration file
file: path=/etc/ntp.conf state=file
==========================================
======================================
=================================================================================
---
# Creating a demo for variables
- name: variable demo
hosts:
vars:
user1:
========================================
---
# Creating a demo for variables
- name: variable demo
hosts: 10.237.4.125
vars:
var_package: telnet
task:
- name: Install telnet package
package: name="{{var_package}}" state=present
-----------------------------------
---
# Creating a demo for variables
- name: variable demo
hosts: 10.237.4.125
vars:
msg: Hello everyone,welcome all
tasks:
- name: Copy the content to the motd text file
copy:
content: |
"{{msg}}"
"{{ansible_memfree_mb}}"
dest: /etc/motd
---
#Creating a demo for variables
- name: variable demo
hosts: 10.237.4.125
vars:
msg: Hello everyone,welcome all
tasks:
- name: Copy the content to the motd text file
copy:
content: |
"{{msg}} {{ansible_memfree_mb}} {{ansible_hostname}}
{{ansible_all_ipv4_addresses}} {{ansible_distribution_file_variety}}
{{ansible_distribution_version}} {{ansible_kernel}}"
dest: /etc/motd
===================================================================================
==
1. Single role
2. Multiple role wirh defined playbook
3. Role with internal dependencies
4. Specific naming
---------------
var_pakg: ntp
var_serv: ntpd
var_file: /etc/ntpd.conf
=================================