JIRA installing and configure on CentOS

Introduction

How to install and configure jira on Centos. Installing and configuring JIRA on CentOS involves a series of systematic steps to set up this popular project management tool effectively. Begin by preparing your CentOS system with the necessary prerequisites, including Java. Then, download and install the JIRA software from Atlassian’s official site. Configuration involves setting up a database, typically PostgreSQL or MySQL, and adjusting the JIRA setup wizard to connect to your newly prepared database. This process ensures that JIRA runs smoothly on CentOS, providing a robust platform for managing your projects. Now, let’s proceed with the JIRA installation and configuration on CentOS.

JIRA installing

Install Java

[vagrant@DevopsRoles ~]$ sudo yum install java-1.8.0-openjdk*

Install MySQL on Centos 7

Link refers to installing MySQL here.

Create a user for installation jira.

[vagrant@DevopsRoles ~]$ sudo useradd jira
[vagrant@DevopsRoles ~]$ sudo passwd jira
[vagrant@DevopsRoles ~]$ echo "jira ALL=(ALL) NOPASSWD:ALL" | sudo tee -a /etc/sudoers
[vagrant@DevopsRoles ~]$ su -l jira
Password:
[jira@DevopsRoles ~]$

Create a temporary install directory:

[jira@DevopsRoles ~]$ mkdir jira && cd jira

Download jira

Link download here:

[jira@DevopsRoles jira]$ wget https://product-downloads.atlassian.com/software/jira/downloads/atlassian-jira-software-8.13.4-x64.bin
[jira@DevopsRoles jira]$ ls -l
total 399948
-rw-rw-r--. 1 jira jira 409545222 Feb 15 11:02 atlassian-jira-software-8.13.4-x64.bin
[jira@DevopsRoles jira]$ chmod u+x atlassian-jira-software-8.13.4-x64.bin
[jira@DevopsRoles jira]$ ./atlassian-jira-software-8.13.4-x64.bin

The result is as follows:

[jira@DevopsRoles jira]$ ./atlassian-jira-software-8.13.4-x64.bin
Unpacking JRE ...
Starting Installer ...
You do not have administrator rights to this machine and as such, some installation options will not be available. Are you sure you want to continue?
Yes [y, Enter], No [n]
y

This will install Jira Software 8.13.4 on your computer.
OK [o, Enter], Cancel [c]
o
Click Next to continue, or Cancel to exit Setup.

Choose the appropriate installation or upgrade option.
Please choose one of the following:
Express Install (use default settings) [1], Custom Install (recommended for advanced users) [2, Enter], Upgrade an existing Jira installation [3]
1

Details on where Jira Software will be installed and the settings that will be used.
Installation Directory: /home/jira/atlassian/jira
Home Directory: /home/jira/atlassian/application-data/jira
HTTP Port: 8080
RMI Port: 8005
Install as service: No
Install [i, Enter], Exit [e]
i

Extracting files ...


Please wait a few moments while Jira Software is configured.

Installation of Jira Software 8.13.4 is complete
Start Jira Software 8.13.4 now?
Yes [y, Enter], No [n]
y

Please wait a few moments while Jira Software starts up.
Launching Jira Software ...

Installation of Jira Software 8.13.4 is complete
Your installation of Jira Software 8.13.4 is now ready and can be accessed
via your browser.
Jira Software 8.13.4 can be accessed at http://localhost:8080
Finishing installation ...
[jira@DevopsRoles jira]$

JIRA’s directory structure looks like this:

[jira@DevopsRoles jira]$ cd ../
[jira@DevopsRoles ~]$ ls -l
total 0
drwxrwxr-x. 4 jira jira 42 Feb 22 14:19 atlassian
drwxrwxr-x. 2 jira jira 52 Feb 22 14:20 jira
[jira@DevopsRoles ~]$ tree -d -L 3 atlassian/
atlassian/
├── application-data
│   └── jira
│       ├── caches
│       ├── data
│       ├── export
│       ├── import
│       ├── log
│       ├── plugins
│       └── tmp
└── jira
    ├── atlassian-jira
    │   ├── aui-examples
    │   ├── decorators
    │   ├── func
    │   ├── images
    │   ├── includes
    │   ├── META-INF
    │   ├── portlets
    │   ├── secure
    │   ├── static
    │   ├── static-assets
    │   ├── styles
    │   ├── template
    │   ├── templates
    │   ├── ui
    │   ├── views
    │   └── WEB-INF
    ├── bin
    ├── conf
    │   └── Catalina
    ├── external-source
    ├── jre
    │   ├── bin
    │   ├── lib
    │   └── man
    ├── lib
    ├── licenses
    ├── logs
    ├── temp
    ├── tomcat-docs
    ├── webapps
    └── work
        └── Catalina

43 directories
[jira@DevopsRoles ~]$

Go to JIRA Installation Directory:

[jira@DevopsRoles ~]$ cd ~/atlassian/jira/
[jira@DevopsRoles jira]$ sudo ./bin/start-jira.sh

start-jira.sh and stop-jira.sh in folder bin

Check JIRA should already be running.

[jira@DevopsRoles jira]$ ps ux | grep jira | grep java | grep -v grep
jira      3184 10.8 24.0 4971344 358732 pts/0  Sl   14:20   0:29 /home/jira/atlassian/jira/jre//bin/java -Djava.util.logging.config.file=/home/jira/atlassian/jira/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Xms384m -Xmx2048m -XX:InitialCodeCacheSize=32m -XX:ReservedCodeCacheSize=512m -Djava.awt.headless=true -Datlassian.standalone=JIRA -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true -Dmail.mime.decodeparameters=true -Dorg.dom4j.factory=com.atlassian.core.xml.InterningDocumentFactory -XX:-OmitStackTraceInFastThrow -Djava.locale.providers=COMPAT -Datlassian.plugins.startup.options= -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Xloggc:/home/jira/atlassian/jira/logs/atlassian-jira-gc-%t.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=20M -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps -XX:+PrintGCCause -XX:+ExplicitGCInvokesConcurrent -Dignore.endorsed.dirs= -classpath /home/jira/atlassian/jira/bin/bootstrap.jar:/home/jira/atlassian/jira/bin/tomcat-juli.jar -Dcatalina.base=/home/jira/atlassian/jira -Dcatalina.home=/home/jira/atlassian/jira -Djava.io.tmpdir=/home/jira/atlassian/jira/temp org.apache.catalina.startup.Bootstrap start

[vagrant@DevopsRoles ~]$ sudo netstat -nplt | grep 8080
tcp6       0      0 :::8080                 :::*                    LISTEN      3184/java

Create user MySQL

mysql -u root -p 
mysql> CREATE DATABASE jiradb CHARACTER SET utf8 COLLATE utf8_bin;
mysql> CREATE USER 'jiradb'@'localhost' IDENTIFIED BY 'Abc123!@#';
mysql> GRANT ALL PRIVILEGES ON jiradb.* TO 'jiradb'@'localhost' WITH GRANT OPTION;

we need a JDBC connector driver for MySQL

[jira@DevopsRoles ~]$ cd && mkdir tmp
[jira@DevopsRoles ~]$ cd tmp/
[jira@DevopsRoles tmp]$ wget http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.29.tar.gz
[jira@DevopsRoles tmp]$ tar xfp mysql-connector-java-5.1.29.tar.gz
[jira@DevopsRoles tmp]$ find mysql-connector-java-5.1.29 -name "mysql-connector-java-*-bin.jar"
mysql-connector-java-5.1.29/mysql-connector-java-5.1.29-bin.jar
[jira@DevopsRoles tmp]$ cp mysql-connector-java-5.1.29/mysql-connector-java-5.1.29-bin.jar ~/atlassian/jira/lib/
[jira@DevopsRoles tmp]$ cd

Restart JIRA

$ sudo ./atlassian/jira/bin/stop-jira.sh
$ sudo ./atlassian/jira/bin/start-jira.sh

Access Browser Jira

Conclusion

JIRA installing and configuring on CentOS. I hope will this your helpful. Thank you for reading the DevopsRoles page!

How to auto create a large csv file with powershell/plsql

Introduction

Creating large CSV files can be a tedious task, especially when dealing with significant amounts of data. PowerShell and PL/SQL offer robust solutions to automate this process, ensuring efficiency and accuracy. In this article, we will explore How to auto create a large csv file with Powershell and plsql, from basic to advanced techniques.

Understanding CSV Files

What is a CSV File?

CSV (Comma-Separated Values) files are plain text files that store tabular data. Each line in the file corresponds to a row in the table, and each value is separated by a comma. These files are widely used for data exchange between systems due to their simplicity and ease of use.

Why Use PowerShell and PL/SQL for CSV Creation?

PowerShell is a task automation and configuration management framework from Microsoft, while PL/SQL is Oracle’s procedural extension for SQL. Both tools offer scripting capabilities that make it easy to automate data handling tasks, including the creation of large CSV files.

Basic Example: Creating a CSV File with PowerShell

Installing PowerShell

PowerShell comes pre-installed on Windows systems. However, if you need the latest version, you can download it from the official PowerShell GitHub page.

Writing a Basic PowerShell Script

Here’s a simple PowerShell script to create a basic CSV file:

# Define the file path
$filePath = "C:\temp\example.csv"

# Create an array of data
$data = @(
[PSCustomObject]@{Name="John"; Age=30; City="New York"},
[PSCustomObject]@{Name="Jane"; Age=25; City="Los Angeles"},
[PSCustomObject]@{Name="Doe"; Age=35; City="Chicago"}
)

# Export the data to a CSV file
$data | Export-Csv -Path $filePath -NoTypeInformation

This script creates a CSV file named example.csv with three rows of sample data.

Running the PowerShell Script

To run the script, save it as CreateCSV.ps1 and execute it in PowerShell:

.\CreateCSV.ps1

Intermediate Example: Adding More Data and Automation

Generating Large Data Sets

To create a larger CSV file, you can generate data programmatically. Here’s an example that generates 10,000 rows of sample data:

# Define the file path
$filePath = "C:\temp\large_example.csv"

# Initialize an array to hold the data
$data = @()

# Generate 10,000 rows of data
for ($i = 1; $i -le 10000; $i++) {
$data += [PSCustomObject]@{Name="User_$i"; Age=(Get-Random -Minimum 20 -Maximum 60); City="City_$i"}
}

# Export the data to a CSV file
$data | Export-Csv -Path $filePath -NoTypeInformation

This script generates a CSV file with 10,000 rows, each containing a unique user name, a random age, and a city.

Scheduling the Script

To automate the execution of your PowerShell script, you can use Task Scheduler on Windows:

  1. Open Task Scheduler.
  2. Create a new task.
  3. Set the trigger (e.g., daily at a specific time).
  4. Set the action to start a program and browse to powershell.exe.
  5. Add arguments: -File "C:\path\to\CreateCSV.ps1"

Advanced Example: Creating Extremely Large CSV Files with PowerShell

To create a large CSV data test using PowerShell:

# Define the count of rows
$count = 9999999999999

# Create a large CSV file
for ($i = 1; $i -le $count; $i++) {
$line = $i.ToString() + "," + "Thora,Temple,2013-05-26 14:47:57"
Add-Content -Path "C:\Users\Hieu\actor_202102111552.csv" -Value $line
}

This script generates a CSV file with a very large number of rows, each containing sequential data.

Advanced Example: Using PL/SQL to Create a Large CSV File

Setting Up Oracle Database

Ensure you have access to an Oracle database and the necessary permissions to create and execute PL/SQL scripts.

Writing a Basic PL/SQL Script

Here’s a basic PL/SQL script to create a CSV file:

DECLARE
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
fileHandler := UTL_FILE.FOPEN('CSV_DIR', 'example.csv', 'W');
UTL_FILE.PUT_LINE(fileHandler, 'Name, Age, City');
UTL_FILE.PUT_LINE(fileHandler, 'John, 30, New York');
UTL_FILE.PUT_LINE(fileHandler, 'Jane, 25, Los Angeles');
UTL_FILE.PUT_LINE(fileHandler, 'Doe, 35, Chicago');
UTL_FILE.FCLOSE(fileHandler);
END;
/

This script creates a CSV file named example.csv in the directory CSV_DIR.

Generating Large Data Sets in PL/SQL

To create a larger CSV file with dynamically generated data:

DECLARE
fileHandler UTL_FILE.FILE_TYPE;
i NUMBER;
BEGIN
fileHandler := UTL_FILE.FOPEN('CSV_DIR', 'large_example.csv', 'W');
UTL_FILE.PUT_LINE(fileHandler, 'Name, Age, City');

FOR i IN 1..10000 LOOP
UTL_FILE.PUT_LINE(fileHandler, 'User_' || i || ', ' || TRUNC(DBMS_RANDOM.VALUE(20, 60)) || ', City_' || i);
END LOOP;

UTL_FILE.FCLOSE(fileHandler);
END;
/

This script generates a CSV file with 10,000 rows, similar to the PowerShell example.

Creating Extremely Large Data Sets in PL/SQL

To create a large data test using PL/SQL:

CREATE OR REPLACE FUNCTION public.insertTable() RETURNS void AS $$
DECLARE
BEGIN
FOR counter IN 1..922337203 LOOP
INSERT INTO public.actor
(first_name, last_name, last_update)
VALUES ('Penelope', 'Guiness', now());
END LOOP;
END;
$$ LANGUAGE plpgsql;

This script inserts a very large number of rows into the public.actor table.

Scheduling the PL/SQL Script

You can use Oracle’s DBMS_SCHEDULER to schedule the execution of your PL/SQL script:

BEGIN
DBMS_SCHEDULER.CREATE_JOB (
job_name => 'CREATE_CSV_JOB',
job_type => 'PLSQL_BLOCK',
job_action => 'BEGIN
fileHandler := UTL_FILE.FOPEN(''CSV_DIR'', ''large_example.csv'', ''W'');
UTL_FILE.PUT_LINE(fileHandler, ''Name, Age, City'');
FOR i IN 1..10000 LOOP
UTL_FILE.PUT_LINE(fileHandler, ''User_'' || i || '', '' || TRUNC(DBMS_RANDOM.VALUE(20, 60)) || '', City_'' || i);
END LOOP;
UTL_FILE.FCLOSE(fileHandler);
END;',
start_date => SYSTIMESTAMP,
repeat_interval => 'FREQ=DAILY; BYHOUR=2; BYMINUTE=0; BYSECOND=0',
enabled => TRUE
);
END;
/

This script schedules the PL/SQL block to run daily at 2:00 AM.

FAQs

What is the best way to handle large CSV files?

Using automation tools like PowerShell and PL/SQL can efficiently handle large CSV files, minimizing manual effort and reducing errors.

How can I optimize the performance of my CSV creation scripts?

Ensure your scripts are optimized by minimizing loops, using bulk operations, and avoiding unnecessary computations. For extremely large files, consider breaking them into smaller chunks.

Can I automate CSV file creation on a schedule?

Yes, both PowerShell and PL/SQL scripts can be scheduled using Task Scheduler on Windows or DBMS_SCHEDULER in Oracle, respectively.

What are some common issues with large CSV files?

Common issues include file size limitations, performance bottlenecks, and data consistency. Using robust scripting and automation can help mitigate these problems.

How do I handle special characters in CSV files?

Ensure your scripts correctly handle special characters by escaping them as needed and using appropriate encoding formats like UTF-8.

Conclusion

auto create a large csv file with Powershell and plsql can be a straightforward process with the right tools and techniques. PowerShell and PL/SQL offer powerful scripting capabilities to automate this task efficiently. By following the examples and tips provided in this guide, you can streamline your CSV file creation process, saving time and reducing errors. Thank you for reading the DevopsRoles page!

Ansible roles directory structure explained

Introduction

I will explain the ansible roles directory structure. The confusing using roles are understanding the file hierarch. Ansible provides a feature called Ansible galaxy that helps you play roles.

For example, Ansible roles directory will look like as below:

[vagrant@ansible_controller demo]$ tree nodejs
nodejs
├── 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

You can be using ansible galaxy it creates a role.

$ sudo ansible-galaxy init <role-name>
# Example init nodejs role
$ sudo ansible-galaxy init nodejs

Explain Ansible directories

  • Tasks: The main list of tasks to be exectued by role. it contains the main.yml file.
  • Files: Contains files that can be deployed by this role
  • Handlers: Contains handlers which may be used by this role or even anywhere outside this role.
  • Defaults: Contains the default variables used by this role.
  • Vars: This directory consists of other variables that used by the roles. These variables can be defined in ansible playbook.
  • Meta: Defines metadata for this role. it contains file role dependencies.

Demo Using Ansible install nodejs

I use ansible-galaxy to download template nodejs role as command below:

[vagrant@ansible_controller demo]$ ansible-galaxy init nodejs

My Ansible structure folder and file as below:

[vagrant@ansible_controller ~]$ tree demo
demo
├── ansible.cfg
├── install-nodejs.yml
├── inventory
│   └── hosts
└── roles
    └── nodejs
        ├── defaults
        │   └── main.yml
        ├── files
        ├── handlers
        │   └── main.yml
        ├── meta
        │   └── main.yml
        ├── README.md
        ├── tasks
        │   └── main.yml
        ├── templates
        └── vars
            └── main.yml

10 directories, 9 files

Write roles/nodejs/tasks/main.yml for nodejs role as below:

---
# Example, tasks file for nodejs
- name: Node.js - Get script
  get_url:
    url: "https://rpm.nodesource.com/setup_10.x"
    dest: "{{ var_node }}/nodejs.sh"

- name: Node.js - Set execution permission to script
  file:
    path: "{{ var_node }}/nodejs.sh"
    mode: "u+x"

- name: Node.js - Execute installation script
  shell: "{{ var_node }}/nodejs.sh"

- name: Node.js - Remove installation script
  file:
    path: "{{ var_node}}/nodejs.sh"
    state: absent

- name: Node.js - Install Node.js
  yum: name={{ item }} state=present update_cache=yes
  with_items:
    - epel-release
    - nodejs

- name: Node.js - Install bower and gulp globally
  npm: name={{ item }} state=present global=yes
  with_items:
    - bower
    - gulp

# check version
- name: "Check if nodejs is installed"
  package_facts:
    manager: "auto"
- name: "nodejs result"
  debug:
     msg: "nodejs found"
  when: "'nodejs' in ansible_facts.packages"
- name: "nodejs result"
  debug:
     msg: "nodejs NOT found"
  when: "'nodejs' not in ansible_facts.packages"

Write your main playbook. Example, install-nodejs.yml file.

---
- hosts: web-server
  become: yes
  vars:
    # variable needed during node installation
    var_node: /tmp
  roles:
       - nodejs

Ansible run command

[vagrant@ansible_controller demo]$ ansible-playbook -i inventory/hosts install-nodejs.yml

The result, install nodejs on the target server as below:

Conclusion

I hope will this your helpful. Thank you for reading the DevopsRoles page!

Ansible copy template file to remote server

#Introduction

How to copy the template file to the remote server using Ansible. I use vagrant to create VMs. My example Ansible creates multiple servers here. In Ansible I use with_fileblob:

Ansible file and folder

[vagrant@ansible_controller ansible]$ tree .
.
├── ansible.cfg
├── copy-template.yml
├── hosts
└── roles
    └── copyfiles
        ├── tasks
        │   └── main.yml
        └── templates
            ├── devopsroles.conf.tmp
            ├── file1.conf.tmp
            └── file2.conf.tmp

4 directories, 7 files

Ansible copy template file to remote server script

copy-template.yml file.

---
- hosts: web-server
  become: yes
  roles:
       - copyfiles

Example: roles/copyfiles/tasks/main.yml file

---
- name: "Copy files template to remote server"
  template:
    src: "{{ item }}"
    dest: "/home/vagrant/dest/{{ item | basename | regex_replace('.tmp','') }}"
    owner: "root"
    group: "root"
    mode: 0644
  with_fileglob:
    - templates/*.tmp

Ansible run command 

[vagrant@ansible_controller ansible]$ ansible-playbook -i hosts copy-template.yml

The output terminal on the ansible controller

[vagrant@ansible_controller ansible]$ ansible-playbook -i hosts copy-template.yml
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [web-server] ***************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
ok: [server1]

TASK [copyfiles : Copy files template to remote server] *************************************************************
changed: [server1] => (item=/home/vagrant/ansible/roles/copyfiles/templates/devopsroles.conf.tmp)
changed: [server1] => (item=/home/vagrant/ansible/roles/copyfiles/templates/file1.conf.tmp)
changed: [server1] => (item=/home/vagrant/ansible/roles/copyfiles/templates/file2.conf.tmp)

PLAY RECAP **********************************************************************************************************
server1                  : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

The result on remote server1.

[vagrant@server1 dest]$ pwd
/home/vagrant/dest
[vagrant@server1 dest]$ ll
total 12
-rw-r--r--. 1 root root 3 Jan 17 08:53 devopsroles.conf
-rw-r--r--. 1 root root 2 Jan 17 08:53 file1.conf
-rw-r--r--. 1 root root 2 Jan 17 08:53 file2.conf

Conclusion

You have to use Ansible copy template file to remote server. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Ansible check package installed in Linux

# Introduction

How to check for a package in the system using Ansible. I use vagrant to create VMs. My example Ansible creates multiple servers here. I will check the Apache package installed in Centos. Now, let’s go Ansible check package installed in Linux.

Ansible check package installed

Ansible file and folder

[vagrant@ansible_controller ~]$ tree .
.
├── ansible
│   ├── ansible.cfg
│   └── hosts
└── check-package.yml

We use the ansible module package_facts

Ansible script

---
- hosts: apache-server
  become: yes
  tasks:
    - name: "Check if APACHE is installed"
      package_facts:
        manager: "auto"
    - name: "Apache result"
      debug:
         msg: "Apache found"
      when: "'httpd' in ansible_facts.packages"
    - name: "Apache result"
      debug:
         msg: "Apache NOT found"
      when: "'httpd' not in ansible_facts.packages"

Ansible run command to check

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts check-package.yml

The output terminal

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts check-package.yml
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [apache-server] ***************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [server1]

TASK [Check if APACHE is installed] *********************************************************************************************************************************************************************************************************
ok: [server1]

TASK [Apache result] ************************************************************************************************************************************************************************************************************************
ok: [server1] => {
    "msg": "Apache found"
}

TASK [Apache result] ************************************************************************************************************************************************************************************************************************
skipping: [server1]

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
server1                  : ok=3    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

I will remove the apache package on server1 apache.

[vagrant@server1 ~]$ sudo yum remove httpd -y

Ansible runs the command to check again:

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts check-package.yml

The output terminal

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts check-package.yml
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [apache-server] ***************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************************************************************************
ok: [server1]

TASK [Check if APACHE is installed] *********************************************************************************************************************************************************************************************************
ok: [server1]

TASK [Apache result] ************************************************************************************************************************************************************************************************************************
skipping: [server1]

TASK [Apache result] ************************************************************************************************************************************************************************************************************************
ok: [server1] => {
    "msg": "Apache NOT found"
}

PLAY RECAP **********************************************************************************************************************************************************************************************************************************
server1                  : ok=3    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

Conclusion

You have to use the Ansible check package installed in Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Securing Sensitive Data with Ansible vault encrypt decrypt Guide

Introduction

In this tutorial, How to use Ansible vault encrypt decrypt to secure sensitive data. you’ll learn how to use Ansible Vault to secure sensitive data within your configurations, an essential skill for maintaining robust security protocols. Ansible Vault encrypts variables and files to protect sensitive information like passwords and credentials from unauthorized access.

The guide covers the initial setup of Ansible Vault, including detailed steps to encrypt your data effectively. You’ll gain insights into the practical applications of these security measures in real-world scenarios.

Finally, the tutorial provides practical tips for decrypting data when necessary for your deployments. Whether you are new to Ansible or have advanced experience, understanding how to manage Vault’s encryption and decryption processes is crucial for enhancing your operational security.

Ansible vault encrypt decrypt

Encrypted files use Ansible Vault

Ansible uses the AES256 algorithm for encrypting sensitivity. We will create an encrypted file using the ansible-vault utility tool as shown.

ansible-vault create pass-file.xml

The content before the Encrypted file is shown.

cat pass-file.xml
welcome to DevopsRoles.com site!

After the Encrypted file as shown.

cat pass-file.xml
$ANSIBLE_VAULT;1.1;AES256
37383139356630386365643264393833663535643534663962643664366634626334383735343861
6265633335646266363233333930303436633063373931380a613635373435366561353534663432
66366631336335393562333233363762633130393336646462633031383239363332616338376633
3630633835646238610a373431323839396636316463633564356535383065626663386135366338
3431

We will view an Encrypted file in Ansible using ansible-vault

ansible-vault view pass-file.xml

Edit an Encrypted file using ansible-vault

ansible-vault edit pass-file.xml

Encrypt an Existing file using the Ansible vault command

ansible-vault encrypt pass-file2.xml

For example the picture below

Decrypting files Ansible

Use an ansible vault to decrypt a file or revert to plain text.

ansible-vault decrypt pass-file2.xml

Reset the Ansible vault password

ansible-vault rekey pass-file2.xml

Encrypt a playbook file in Ansible

Example Ansible Setup NFS server here. I will Encrypt file exports.j2 the content as below:

[vagrant@ansible_controller ~]$ cat ./ansible/exports.j2
# /etc/exports: the access control list for filesystems which may be exported
#   to NFS clients.  See exports(5).
/home/vagrant/nfs_test            192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)

Encryption with vault_pass.txt as below:

[vagrant@ansible_controller ~]$ cat vault_pass.txt
123456789@
[vagrant@ansible_controller ~]$ ansible-vault encrypt ./ansible/exports.j2 --vault-password-file vault_pass.txt
Encryption successful
[vagrant@ansible_controller ~]$ cat ./ansible/exports.j2
$ANSIBLE_VAULT;1.1;AES256
38376166636635393464306333653230663865303966626137346536393231623862333532313061
6334326531333734663936336436323034643261666462640a353833363437633761656136306433
30383331633836346563323962346663373664646538636135663866346435643834613937643664
3763383131363761370a363632613539303239366166613339663133653938646665613530633633
64613233636434323031326137376636613536396330623338326230366664376339653431643831
63386431633837643265343662643338626339656630336666613565303738643038373131383530
61383637666462376663306536333736623339346364653462633730383961353531613830343534
66393339363061643861373162663832333561663763313339626365353139376433303333373133
65373461313531323735623135616535363638353963343563643439363461613236646433313461
39653733633638396663636236346638393036323831386535333933373764616334343431316234
31376537653434653931613931646465393638373039363335616364613638633264356531323332
65336164333334303765393361616233373138663530386466383032333334393465363632303435
64383332313635326661333431613561666431356331363963633137623965323963666338393865
3235393266326566663463363861613166643130313430653736

As a result, run the Ansible playbook as below:

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts nfs-server.yml --vault-password-file vault_pass.txt
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [nfs-server] ***************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
ok: [servernfs]

TASK [install nfs-utils] ********************************************************************************************
ok: [servernfs]

TASK [Create a mountable directory if it does not exist] ************************************************************
ok: [servernfs]

TASK [enable rpcbind nfslock nfs] ***********************************************************************************
ok: [servernfs] => (item=rpcbind)
ok: [servernfs] => (item=nfslock)
ok: [servernfs] => (item=nfs)

TASK [Copy exports file.] *******************************************************************************************
changed: [servernfs]

TASK [NFS system start] *********************************************************************************************
changed: [servernfs]

PLAY RECAP **********************************************************************************************************
servernfs                  : ok=6    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

File /etc/exports on server NFS as below:

[vagrant@servernfs ~]$ cat /etc/exports
# /etc/exports: the access control list for filesystems which may be exported
#   to NFS clients.  See exports(5).
/home/vagrant/nfs_test            192.168.1.0/24(rw,sync,no_root_squash,no_subtree_check)

Conclusion

In conclusion, using Ansible Vault for encryption and decryption is a key skill for safeguarding your sensitive data in DevOps environments. The examples provided in this guide illustrate practical applications of Ansible Vault, enhancing your security practices. We hope you find this information beneficial. Thank you for reading on the DevopsRoles page!

Ansible Setup NFS server and client

#Introduction

In this tutorial, How to set up an NFS server and client using Ansible. I use Vagrant. In my example, Ansible creates multiple servers here. Now, let’s go to the Ansible Setup NFS server and client.

Ansible file and folder

[vagrant@ansible_controller ~]$ tree .
.
├── ansible
│   ├── ansible.cfg
│   ├── exports.j2
│   └── hosts
├── nfs-client.yml
└── nfs-server.yml

1 directory, 5 files

Ansible script

nfs-server.yml file for NFS Server as below

---
- hosts: nfs-server
  become: yes
  tasks:
    - name: install nfs-utils
      yum: name=nfs-utils state=latest

    - name: Create a mountable directory if it does not exist
      file:
        path: /home/vagrant/nfs_test
        state: directory
        owner: vagrant
        group: vagrant
        mode: '0775'
    - name: enable rpcbind nfslock nfs
      service:
        name: "{{ item }}"
        enabled: yes
      with_items:
        - rpcbind
        - nfslock
        - nfs
    - name: Copy exports file.
      template:
        src: ./ansible/exports.j2
        dest: /etc/exports
        owner: root
        group: root
        mode: 0644
    - name: NFS apply change configrue
      shell: systemctl reload nfs;exportfs -a

nfs-client.yml file for nfs clients as below

---
- hosts: nfs-clients
  become: yes
  tasks:
    - name: install nfs-utils
      yum: name=nfs-utils state=latest

    - name: Create a mountable directory if it does not exist
      file:
        path: /mnt/web_storage
        state: directory
        owner: vagrant
        group: vagrant
        mode: '0775'
    - name: Mount volumn
      shell: sudo mount 192.168.3.9:/home/vagrant/nfs_test /mnt/web_storage

exports.j2 file with content as below

# /etc/exports: the access control list for filesystems which may be exported
#   to NFS clients.  See exports(5).
/mnt/nfs_test            *(rw,sync,no_root_squash,no_subtree_check)

My example hosts file as below

[nfs-server]
servernfs

[nfs-clients]
server1

File ansible/ansible.cfg example as below

[defaults]
inventory = ./hosts
forks = 15
log_path=$HOME/ansible/ansible.log
host_key_chcking = False
gathering = smart

Ansible run command for NFS server

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts nfs-server.yml

The output terminal as picture below

Ansible run command for NFS client

[vagrant@ansible_controller ~]$ ansible-playbook -i ansible/hosts nfs-client.yml

The output terminal as picture below

Conclusion

You have to use ansible setup NFS server and NFS client. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Vagrant No VirtualBox Guest Additions installation found [Fixed]

Introduction

In this tutorial, How to fix the error Vagrant No VirtualBox Guest Additions installation is found. I use a laptop and run the command vagrant up for the NFS server then the error “umount: /mnt: not mounted

ERROR umount: /mnt: not mounted

E:\Vagrant_VMS\NFS_server>vagrant up 

Error: Nothing to do
Unmounting Virtualbox Guest Additions ISO from: /mnt
umount: /mnt: not mounted
==> servernfs: Checking for guest additions in VM...
    servernfs: No guest additions were detected on the base box for this VM! Guest
    servernfs: additions are required for forwarded ports, shared folders, host only
    servernfs: networking, and more. If SSH fails on this machine, please install
    servernfs: the guest additions and repackage the box to continue.
    servernfs:
    servernfs: This is not an error message; everything may continue to work properly,
    servernfs: in which case you may ignore this message.
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

umount /mnt

Stdout from the command:



Stderr from the command:

umount: /mnt: not mounted

Vagrant No VirtualBox Guest Additions installation found fixed

I have uninstalled vagrant-vbguest and installed vagrant-vbguest.

vagrant plugin uninstall vagrant-vbguest
vagrant plugin install vagrant-vbguest --plugin-version 0.21

The output uninstall and install vagrant-vbguest as below

E:\Vagrant_VMS\NFS_server>vagrant plugin uninstall vagrant-vbguest
Uninstalling the 'vagrant-vbguest' plugin...
Successfully uninstalled micromachine-3.0.0
Successfully uninstalled vagrant-vbguest-0.27.0

E:\Vagrant_VMS\NFS_server>vagrant plugin install vagrant-vbguest --plugin-version 0.21
Installing the 'vagrant-vbguest --version '0.21'' plugin. This can take a few minutes...
Fetching micromachine-3.0.0.gem
Fetching vagrant-vbguest-0.21.0.gem
Installed the plugin 'vagrant-vbguest (0.21.0)'!

As a result, I have to fix it!

E:\Vagrant_VMS\NFS_server>vagrant reload
==> servernfs: Attempting graceful shutdown of VM...
==> servernfs: Checking if box 'centos/7' version '2004.01' is up to date...
==> servernfs: Clearing any previously set forwarded ports...
==> servernfs: Clearing any previously set network interfaces...
==> servernfs: Preparing network interfaces based on configuration...
    servernfs: Adapter 1: nat
    servernfs: Adapter 2: hostonly
==> servernfs: Forwarding ports...
    servernfs: 22 (guest) => 2222 (host) (adapter 1)
==> servernfs: Booting VM...
==> servernfs: Waiting for machine to boot. This may take a few minutes...
    servernfs: SSH address: 127.0.0.1:2222
    servernfs: SSH username: vagrant
    servernfs: SSH auth method: private key
    servernfs: Warning: Connection aborted. Retrying...
==> servernfs: Machine booted and ready!
[servernfs] GuestAdditions 6.1.14 running --- OK.
==> servernfs: Checking for guest additions in VM...
==> servernfs: Configuring and enabling network interfaces...
==> servernfs: Rsyncing folder: /cygdrive/e/MyData/Vagrant_VMS/NFS_server/ => /vagrant
==> servernfs: Rsyncing folder: /cygdrive/e/MyData/Vagrant_VMS/NFS_server/NFS_Volumn/ => /home/vagrant/nfs_test
==> servernfs: Machine already provisioned. Run `vagrant provision` or use the `--provision`
==> servernfs: flag to force provisioning. Provisioners marked to run always will still run.

Youtube Vagrant No VirtualBox Guest Additions installation found [Fixed]

Conclusion

You have fixed Vagrant No VirtualBox. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Ansible get IP address remote server

#Introduction

In this tutorial, How to use Ansible get IP address remote server. There are many methods to obtain the IP address the current of remote hosts. so let us learn how to use Ansible to get an IP address to remote hosts’ servers.

Structure file and folder Ansible get IP address remote server

[vagrant@ansible_controller ~]$ pwd
/home/vagrant
[vagrant@ansible_controller ~]$ tree .
.
├── ansible
│   ├── ansible.cfg
│   └── hosts
└── getIP.yml

1 directory, 3 files

Option 1: use hostvars

To retrieve the IP address of a remote server using Ansible, you can use the ansible_default_ipv4 variable. This variable provides information about the default IPv4 address of the target host.

For example the content file getIP.yml as below

[vagrant@ansible_controller ~]$ cat getIP.yml
---
- hosts: servers
  tasks:
  - name: Test hosts list
    debug:
      msg: "{{ hostvars[inventory_hostname]['ansible_default_ipv4']['address'] }}"

The output on terminal

[vagrant@ansible_controller ~]$ ansible-playbook getIP.yml -i .ansible/hosts

PLAY [servers] *********************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [server1]

TASK [Test hosts list] *************************************************************************************************
ok: [server1] => {
    "msg": "10.0.2.15"
}

PLAY RECAP *************************************************************************************************************
server1                    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Here’s an example of how you can access the IP address:

Option 2: Other

For example the content file getIP.yml as below

[vagrant@ansible_controller ~]$ cat getIP.yml
---
- hosts: servers
  gather_facts: yes
  tasks:
  - name: Get IP address remote server
    debug:
      msg: "{{ hostvars[inventory_hostname]['ansible_env'].SSH_CONNECTION.split(' ')[2] }}"

The output on terminal

[vagrant@ansible_controller ~]$ ansible-playbook getIP.yml -i .ansible/hosts

PLAY [servers] *************************************************************************************************************

TASK [Gathering Facts] *************************************************************************************************
ok: [server1]

TASK [Get IP address remote server] ************************************************************************************
ok: [server1] => {
    "msg": "192.168.3.11"
}

PLAY RECAP *************************************************************************************************************
server1                    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Option 3: lookup and dig

For example the content file getIP.yml as below

[vagrant@ansible_controller ~]$ cat getIP.yml
---
- hosts: servers
  tasks:
  - name: Test hosts list
    debug:
      msg: "{{ lookup('dig', ansible_host) }}"

Make sure you have proper SSH access to the remote server and the necessary permissions to gather facts from it.

Conclusion

You have to use Ansible get IP address remote server. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Command creating a virtual machine in vagrant

#Introduction

In this tutorial, I have written The commands when creating a virtual machine in VirtualBox using Vagrant.

Prerequisites

  • VirtualBox Installed
  • Vagrant Installed

The first, command at the time of creating

The box is searched from Vagrant Cloud.

Create a directory for the virtual machine you want to create and change to it.

mkdir vagrant_test
cd vagrant_test

Initialize the directory and create a Vagrantfile.

vagrant init ubuntu/trusty64

The contents should be as follows. If the box name is different, rewrite it.

cat Vagrantfile
Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/trusty64"
end

Start the virtual machine. A box has been added at this time.

vagrant up

ssh connection

vagrant ssh

Other used commands Vagrant

Add box

vagrant box add your-box-name

Added box list

vagrant box list

Delete box

vagrant box remove your-box-name

Virtual machine shutdown

vagrant halt

Delete virtual machine

vagrant destroy

Check virtual machine status

vagrant status

Conclusion

You have to use Command creating a virtual machine in vagrant. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Devops Tutorial

Exit mobile version