GithubHelp home page GithubHelp logo

nagiosxi-hostclone's Introduction

Create project

Once we have our Ansible environment ready, next create a project. I will create a new project to demonstrate ansible roles example:

Step 1: Create ansible role - nagiosxi-hostclone

To create ansible role, use ansible-galaxy init <role_name> to create the role directory structure. We will create the role inside our /roles directory i.e. ~/nagiosxi-hostclone/roles

[root@ansbile nagiosxi-hostclone~]$ mkdir roles
[root@ansible ~]$ cd roles

Next use ansible-galaxy init command to create ansible role. We will create nagiosxi-hostclone role:

[root@ansible roles]$ ansible-galaxy init roles

  • roles was created successfully
[root@ansible roles]$ tree roles
nagiosxi-hostclone
├── defaults
│   └── main.yml
├── files
├── handlers
│   └── main.yml
├── meta
│   └── main.yml
├── README.md
├── tasks
│   └── main.yml
├── templates
├── tests
│   ├── inventory
│   └── test.yml
└── vars
    └── main.yml

8 directories, 8 files

Step 2: Create ansible tasks

[root@ansible roles]$ cat tasks/main.yml 
---
# tasks file for agiosxi-hostclone
- name: Create Nagiosxi file 
  template:
    src: "{{ templet }}"
    dest: "/usr/local/nagios/etc/import/{{ fqdn }}.cfg"
  notify: import nagios config
  notify: Restart the nagios config

Step 3: Create ansible template

Next we will create the template content which will be used to update host clonning in our ansible roles examples. I will create a new template file under templates directory using some variables:

[root@ansible roles]$ cat templates/nagios-hosts.cfg.j2 
###############################################################################
#
# Hosts configuration file
#
# Created by: Nagios CCM 3.0.6
# Date:       2020-07-19 12:38:25
# Version:    Nagios Core 4.x
#
# --- DO NOT EDIT THIS FILE BY HAND --- 
# Nagios CCM will overwrite all manual settings during the next update if you 
# would like to edit files manually, place them in the 'static' directory or 
# import your configs into the CCM by placing them in the 'import' directory.
#
###############################################################################

define host {
    host_name                   {{ fqdn }}
    use                         xiwizard_linuxsnmp_host
    address                     {{ fqdn_address }}
    max_check_attempts          1
    check_interval              5
    retry_interval              5
    check_period                xi_timeperiod_24x7
    contacts                    nagiosadmin
    notification_interval       0
    notification_period         xi_timeperiod_24x7
    first_notification_delay    0
    notification_options        d,u,r,f,
    notifications_enabled       1
    register                    1
}

###############################################################################
#
# Hosts configuration file
#
# END OF FILE
#
###############################################################################

Step 4: Create ansible variables

We will use defaults folder to define custom variables which is used in our template file templates/<templete.cfg.j2>

[root@ansible roles]$ cat defaults/main.yml 
---
fqdn: "{{ fqdn }}"
fqdn_address: "{{ fqdn_address }}"

# Step 5 : Remove unwanted directories (Optional)
This step is completely optional. In this ansible roles example we will not use other directories so we are deleting them. After deleting the additional directories you can use tree command to list the directory structure of agiosxi-hostclone roles

copy
[root@ansible roles]$ rm -rf tests vars
[root@ansible roles]$ tree
.
├── README.md
├── add-nagiosxi-monitoring.yml
├── ansible.cfg
├── gitlab
│   ├── README.md
│   └── ansibleplaybook-git
├── inventory
└── roles
    └── nagiosxi-monitoring
        ├── defaults
        │   └── main.yml
        ├── files
        ├── handlers
        │   └── main.yml
        ├── meta
        │   └── main.yml
        ├── tasks
        │   └── main.yml
        └── templates
            ├── nagios-hosts.cfg.j2
            ├── nagiosxi-hosts.cfg.j2
            ├── nagiosxi-ja-services.cfg.j2
            └── nagiosxi-servicest.cfg.j2

10 directories, 13 files

Step 6: Create ansible role playbook

Now after you create ansible role structure, we need a playbook file which will deploy the role to our managed hosts. I will create my playbook file add-nagiosxi-monitoring.yml under nagiosxi-hostclone project directory.

[root@ansible nagiosxi-hostclone]$ cat add-nagiosxi-monitoring.yml 
---
- name: Nagiosxi host using agiosxi-hostclone
  hosts: all
  user: root
  become: true

  roles:
    - role: nagiosxi-monitoring

==========================================================================================================================================================

nagios-monitor Role

Valid targets

  • Nagiosxi-Monitoring:
    • This also role interacts with: The Nagios server specified with the nagios_server variable

System state after applying

  • Nagios Host and Nagios Services are configured for target host

Usage

Expects

  • Expects fact gathering

Configure standard set of Nagios checks for a new general-purpose VM

---
- name: Nagiosxi host clonning using Asnsible playbook
  hosts: all
  user: root
  become: true
  roles:
    - role: nagiosxi-monitoring

Running the play book:

Command:

ansible-playbook -e "fqdn=<FQDN Host Name> fqdn_address=<IP Address for host> templet=<Templet to clone the host and services>" add-nagiosxi-monitoring.yml

Example to clone host:

ansible-playbook -e "fqdn=batfs-21-hyd.jonnalas.com fqdn_address=192.168.0.103 templet=nagiosxi-hosts.cfg.j2" add-nagiosxi-monitoring.yml

Examnple to clone the services:

ansible-playbook -e "fqdn=batfs-21-hyd.jonnalas.com fqdn_address=192.168.0.103 templet=nagiosxi-service.cfg.j2" add-nagiosxi-monitoring.yml

nagiosxi-hostclone's People

Contributors

swagathj avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.