Monday, August 19, 2024

Menu Creation

 <!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Custom Navbar with Animation</title>

    <!-- Bootstrap CSS -->

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Font Awesome -->

    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">

    <!-- Custom CSS -->

    <style>

        /* Add hover animation to menu items */

        .nav-link {

            transition: color 0.3s, transform 0.3s;

        }

        .nav-link:hover {

            color: #0d6efd; /* Bootstrap primary color */

            transform: scale(1.1); /* Slight zoom on hover */

        }


        /* Ensure the dropdown menu animates */

        .dropdown-menu {

            opacity: 0;

            transform: translateY(10px);

            transition: opacity 0.3s ease, transform 0.3s ease;

        }


        .dropdown:hover .dropdown-menu {

            display: block;

            opacity: 1;

            transform: translateY(0);

        }

    </style>

</head>

<body>

    <!-- Navbar -->

    <nav class="navbar navbar-expand-lg navbar-light bg-light">

        <div class="container-fluid">

            <!-- Brand Logo -->

            <a class="navbar-brand" href="#">

                <img src="logo.png" alt="Logo" width="40" height="40">

            </a>


            <!-- Toggle button for mobile view -->

            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">

                <span class="navbar-toggler-icon"></span>

            </button>


            <!-- Navbar Links -->

            <div class="collapse navbar-collapse" id="navbarNav">

                <ul class="navbar-nav mx-auto">

                    <li class="nav-item">

                        <a class="nav-link active" aria-current="page" href="#"><i class="fas fa-tachometer-alt"></i> Dashboard</a>

                    </li>

                    <li class="nav-item">

                        <a class="nav-link" href="#"><i class="fas fa-graduation-cap"></i> Learn</a>

                    </li>

                    <li class="nav-item">

                        <a class="nav-link" href="#"><i class="fas fa-trophy"></i> Leaderboard</a>

                    </li>

                    <li class="nav-item">

                        <a class="nav-link" href="#"><i class="fas fa-bookmark"></i> Bookmarks</a>

                    </li>

                    <li class="nav-item">

                        <a class="nav-link" href="#"><i class="fas fa-sticky-note"></i> Posts</a>

                    </li>

                    <li class="nav-item">

                        <a class="nav-link" href="#"><i class="fas fa-store"></i> Store</a>

                    </li>

                    <li class="nav-item">

                        <a class="nav-link" href="#"><i class="fas fa-question-circle"></i> Doubts</a>

                    </li>

                </ul>


                <!-- User Profile Dropdown -->

                <ul class="navbar-nav">

                    <li class="nav-item dropdown">

                        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">

                            <img src="profile-pic.png" alt="User" class="rounded-circle" width="30" height="30">

                        </a>

                        <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">

                            <li><span class="dropdown-item-text">Signed in as <strong>User Name</strong></span></li>

                            <li><hr class="dropdown-divider"></li>

                            <li><a class="dropdown-item" href="#">Your Profile</a></li>

                            <li><a class="dropdown-item" href="#">Login Activity</a></li>

                            <li><a class="dropdown-item" href="#">Your Report</a></li>

                            <li><hr class="dropdown-divider"></li>

                            <li><a class="dropdown-item" href="#">Logout</a></li>

                        </ul>

                    </li>

                </ul>

            </div>

        </div>

    </nav>


    <!-- Bootstrap JS and dependencies -->

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

</body>

</html>

Wednesday, April 12, 2023

Copy Tar file to destination servers and udate IPs based on remote name with fQDN

 

- name: Copy and untar tarball

  hosts: all

  become: yes

  tasks:

    - name: Copy tarball

      copy:

        src: /home/osboxes/project-1/httpd-2.4.57.tar.gz

        dest: /opt/myapp/httpd-2.4.57.tar.gz


    - name: Unarchive httpd tar.gz file

      unarchive:

        src: /opt/myapp/httpd-2.4.57.tar.gz

        dest: /opt/myapp/

        remote_src: yes

        extra_opts: "-z"      

      

    - name: Copy file

      copy:

        src: /home/osboxes/project-1/test.properties

        dest: /opt/myapp/httpd-2.4.57/test.properties

        mode: 0644


    - name: Update hostname property

      lineinfile:

        path: /opt/myapp/httpd-2.4.57/test.properties

        regex: '^domainname='

        line: 'domainname={{ inventory_hostname }}.example.com'

      register: update_result


    - name: Show update result

      debug:

        var: update_result


Monday, February 13, 2023

Customize Ansible Behaviour

The default location of ansible.cfg file is /etc/ansible/ansible.cfg

The ansible.cfg file is the main configuration file for Ansible. It specifies the configuration options for an Ansible deployment. The sections in the ansible.cfg file include:

  1. Default Settings: This section contains default settings for Ansible such as the location of the inventory file, the library path, and the SSH user.

  2. Inventory: This section contains options for configuring the inventory file, including the host file, the pattern to match hosts, and the SSH user.

  3. Privilege Escalation: This section contains options for privilege escalation, including the default become method, the default become user, and the default become flags.

  4. Connections: This section contains options for configuring the connection method, including the transport, the connection timeout, and the retries.

  5. Module Configuration: This section contains options for configuring the module behavior, including the library path, the default module path, and the maximum module execution time.

  6. Plugins: This section contains options for configuring the plugins, including the callback plugin directory and the filter plugin directory.

  7. SSH Options: This section contains options for configuring the SSH connection, including the SSH user, the SSH key file, and the SSH timeout.

  8. Output Options: This section contains options for configuring the output of Ansible, including the verbosity, the color output, and the output format.

  9. Strategy Options: This section contains options for configuring the strategy for executing tasks, including the strategy, the forking, and the strategy plugins.

Each of these sections can be customized to meet your specific needs and requirements. It's important to note that these settings can be overridden by settings in other configuration files or on the command line.


here's an example of a complete ansible.cfg file with all the sections and options I mentioned:


# Default Settings [defaults] inventory = ./inventory library = /usr/share/ansible/library remote_user = ansible # Inventory [inventory] enable_plugins = ini, virtualbox, yaml host_pattern = ^[a-zA-Z0-9._-]+$ # Privilege Escalation [privilege_escalation] become = True become_method = sudo become_user = root become_ask_pass = False # Connections [connection] transport = ssh timeout = 10 retries = 3 # Module Configuration [module_defaults] library = /usr/share/ansible/library module_path = /usr/share/ansible/modules module_timeout = 30 # Plugins [plugins] callback_whitelist = timer filter_plugins = /usr/share/ansible/plugins/filter # SSH Options [ssh_connection] ssh_user = ansible ssh_key_file = ~/.ssh/id_rsa ssh_timeout = 10 # Output Options [output] verbosity = 2 colored = True format = json # Strategy Options [strategy] strategy = linear forks = 5 strategy_plugins = /usr/share/ansible/plugins/strategy






Host File

 Host file can be like any of this format 

 how to open host file with default location

vi /etc/ansible/host





[dev]

node1

node2

node3

[test]

node4:22 ansible_connection=ssh ansible_user=jamesbond

[ipbase]

192.168.2.[0:10]

# from IP 192.168.2.0 to IP 192.168.2.10 IP will be covered




[serversname]

server[01:25].mydomain.com

#servername will shows from server01.mydomain.com to server05.mydomain.com




Ansible Commands

 1. Basic Command in Ansible


2. list all hosts 

Default path of hosts: /etc/ansible/hosts

    command: ansible --list-hosts all

3. Ping test on all hosts

    command: ansible -m ping all

4. 

Monday, January 30, 2023

All In One Ansible Playbooks

 ---

- name: All-in-One Ansible Playbook

  hosts: localhost

  become: yes

  vars:

    user_name: john

    file_path: /tmp/test.txt

    pkg_name: nginx

  tasks:

    - name: Create a new user

      user:

        name: "{{ user_name }}"

        state: present

        shell: /bin/bash


    - name: Install a package

      package:

        name: "{{ pkg_name }}"

        state: present


    - name: Create a file

      file:

        path: "{{ file_path }}"

        state: touch


    - name: Copy a file from local to remote

      copy:

        src: /path/to/local/file

        dest: /path/to/remote/file


    - name: Fetch a file from remote to local

      fetch:

        src: /path/to/remote/file

        dest: /path/to/local/file


    - name: Show system memory info

      shell: "free -m"

      register: memory_info


    - name: Display memory info

      debug:

        var: memory_info


    - name: Check if a package is installed

      shell: "dpkg -l | grep {{ pkg_name }}"

      register: pkg_check_result

      ignore_errors: yes


    - name: Display the package installation status

      debug:

        msg: "{{ pkg_name }} is installed"

      when: pkg_check_result.rc == 0


    - name: Delete a user

      user:

        name: "{{ user_name }}"

        state: absent


Sunday, January 29, 2023

Start with basic Ansible Playbook

This is basic playbook to ping your localhost (Controller node)



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

---
- name: "My First Playbook"
  hosts: localhost
 
  tasks:
  - name: "test connectivity"
    ping:
   

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

Ad-hoc task for same playbook

command: ansible localhost -m ping



#ansible

#ansibleAutomation


 

Menu Creation

 <!DOCTYPE html> <html lang="en"> <head>     <meta charset="UTF-8">     <meta name="view...