ansible Archives - DBACLASS https://dbaclass.com/article-category/ansible/ database administration Tue, 06 Jul 2021 19:09:44 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.5 Automate oracle client installation using ansible https://dbaclass.com/article/automate-oracle-client-installation-using-ansible/ https://dbaclass.com/article/automate-oracle-client-installation-using-ansible/#respond Tue, 06 Jul 2021 19:00:48 +0000 https://dbaclass.com/?post_type=article&p=7102 We can use the power of ansible to automate the oracle client installation task on multiple servers.In this article, we will explain how we will achieve this by executing an ansible playbook from ansible control node.   Ansible control node  is any machine where ansible tool is installed.    IMPORTANT POINTS: oracle 19c client will […]

The post Automate oracle client installation using ansible appeared first on DBACLASS.

]]>
We can use the power of ansible to automate the oracle client installation task on multiple servers.In this article, we will explain how we will achieve this by executing an ansible playbook from ansible control node.

 

Ansible control node  is any machine where ansible tool is installed. 

 

IMPORTANT POINTS:

  1. oracle 19c client will be installed on all nodes.
  2. Make sure  the servers where  client need to be installed has connectivity from ansible control server

Below are the steps :

1. Copy the oracle 19c client software ( zip file ) to ansible control server.


[ansible_node] ls -ltr /oracle/LINUX.X64_193000_client.zip

2. Prepare the inventory file:

The list of servers where oracle 19c client will be installed.

[ansiblel_node] $ cat /home/ansible/ansible-scipts/host_inv
[appserver]
linux_host22 ansible_host=10.20.86.60 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host29 ansible_host=10.20.86.61 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host34 ansible_host=10.20.86.62 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123

3. Prepare the client installation response file:

[ansible_node] $ cat /home/ansible/oracle_client_19c.rsp

#-------------------------------------------------------------------------------
# Do not change the following system generated value.
#-------------------------------------------------------------------------------
oracle.install.responseFileVersion=/oracle/install/rspfmt_clientinstall_response_schema_v19.0.0

#-------------------------------------------------------------------------------
# Unix group to be set for the inventory directory.
#-------------------------------------------------------------------------------
UNIX_GROUP_NAME=oinstall
#-------------------------------------------------------------------------------
# Inventory location.
#-------------------------------------------------------------------------------
INVENTORY_LOCATION=/oracle/app/oraInventory
#-------------------------------------------------------------------------------
# Complete path of the Oracle Home
#-------------------------------------------------------------------------------
ORACLE_HOME=/oracle/app/oracle/product/19c/client_1
#-------------------------------------------------------------------------------
# Complete path of the Oracle Base.
#-------------------------------------------------------------------------------
ORACLE_BASE=/oracle/app/oracle
oracle.install.client.installType=Administrator

#-------------------------------------------------------------------------------

4. Prepare the ansible playbook:

[ansible_node] $ cat oracle_client_installation.yml
- hosts: appserver
  strategy: free
  user: bvunix
  become: yes
  become_method: su
  become_user: oracle
  tasks:
    - name: check existance of mount point
      command: mountpoint -q /oracle
      register: volume_stat
      failed_when: False
    - name: Copy client software
      unarchive: src=/oracle/LINUX.X64_193000_client.zip dest=/oracle/
    - name: Copy response file
      copy: src=/home/ansible/oracle_client_19c.rsp dest=/oracle mode=0777
    - name: Install Oracle Client
      command: "/oracle/client/runInstaller -silent -showProgress -ignorePrereq -ignoreSysPrereqs -waitforcompletion -responseFile /oracle/oracle_client_19c.rsp"
      register: client_runinstaller_output
      failed_when: "'Successfully Setup Software' not in client_runinstaller_output.stdout"


5. Execute the playbook:

[ansible-node]$  ansible-playbook oracle_client_installation.yml -i /home/ansible/ansible-scipts/host_inv

PLAY [linux_host22,linux_host29,linux_host34] ***********************************************************************************************************************************
Tuesday 06 July 2021  20:30:15 +0300 (0:00:00.048)       0:00:00.048 **********
Tuesday 06 July 2021  20:30:15 +0300 (0:00:00.011)       0:00:00.060 **********
Tuesday 06 July 2021  20:30:15 +0300 (0:00:00.010)       0:00:00.071 **********

TASK [Gathering Facts] **********************************************************************************************************************************************************
[WARNING]: Module remote_tmp /home/oracle/.ansible/tmp did not exist and was created with a mode of 0700, this may cause issues when running as another user. To avoid this,
create the remote_tmp dir with the correct permissions manually
ok: [linux_host34]
ok: [linux_host22]
Tuesday 06 July 2021  20:30:18 +0300 (0:00:02.977)       0:00:03.048 **********
Tuesday 06 July 2021  20:30:18 +0300 (0:00:00.043)       0:00:03.091 **********

TASK [check existance of mount point] *******************************************************************************************************************************************
changed: [linux_host34]
Tuesday 06 July 2021  20:30:19 +0300 (0:00:01.304)       0:00:04.397 **********
changed: [linux_host22]
Tuesday 06 July 2021  20:30:19 +0300 (0:00:00.088)       0:00:04.486 **********

TASK [Gathering Facts] **********************************************************************************************************************************************************
ok: [linux_host29]
Tuesday 06 July 2021  20:30:20 +0300 (0:00:00.884)       0:00:05.370 **********

TASK [check existance of mount point] *******************************************************************************************************************************************
changed: [linux_host29]
Tuesday 06 July 2021  20:30:21 +0300 (0:00:01.329)       0:00:06.699 **********

TASK [Copy client software] *****************************************************************************************************************************************************
changed: [linux_host34]
Tuesday 06 July 2021  20:31:36 +0300 (0:01:14.560)       0:01:21.259 **********
changed: [linux_host22]
Tuesday 06 July 2021  20:31:38 +0300 (0:00:02.122)       0:01:23.382 **********

TASK [Copy response file] *******************************************************************************************************************************************************
changed: [linux_host34]
Tuesday 06 July 2021  20:31:40 +0300 (0:00:01.840)       0:01:25.222 **********
changed: [linux_host22]
Tuesday 06 July 2021  20:31:41 +0300 (0:00:01.072)       0:01:26.295 **********

TASK [Copy client software] *****************************************************************************************************************************************************
changed: [linux_host29]
Tuesday 06 July 2021  20:31:45 +0300 (0:00:04.660)       0:01:30.956 **********

TASK [Copy response file] *******************************************************************************************************************************************************
changed: [linux_host29]
Tuesday 06 July 2021  20:31:48 +0300 (0:00:02.787)       0:01:33.744 **********

TASK [Install Oracle Client] ****************************************************************************************************************************************************
changed: [linux_host22]
changed: [linux_host34]
changed: [linux_host29]

PLAY RECAP **********************************************************************************************************************************************************************
linux_host22               : ok=5    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
linux_host29               : ok=5    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
linux_host34               : ok=5    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

Tuesday 06 July 2021  20:33:33 +0300 (0:01:45.191)       0:03:18.935 **********
===============================================================================
Install Oracle Client -------------------------------------------------------------------------------------------------------------------------------------------------- 105.19s
Copy client software ---------------------------------------------------------------------------------------------------------------------------------------------------- 74.56s
Gathering Facts ---------------------------------------------------------------------------------------------------------------------------------------------------------- 2.98s
Copy response file ------------------------------------------------------------------------------------------------------------------------------------------------------- 2.79s
check existance of mount point ------------------------------------------------------------------------------------------------------------------------------------------- 1.33s

We have successfully installed oracle client on all the mentioned servers.

The post Automate oracle client installation using ansible appeared first on DBACLASS.

]]>
https://dbaclass.com/article/automate-oracle-client-installation-using-ansible/feed/ 0
How to create host configuration report using ansible-cmdb https://dbaclass.com/article/how-to-create-host-configuration-report-using-ansible-cmdb/ https://dbaclass.com/article/how-to-create-host-configuration-report-using-ansible-cmdb/#comments Wed, 16 Jun 2021 17:31:43 +0000 https://dbaclass.com/?post_type=article&p=6935 ansible-cmdb tool can be used to create system configuration report of your host inventory in different formats like html,csv, json,sql etc.  Let’s go through the below demonstration . Lets say you have hundreds of servers and you can want to generate a report that has server overview details like cpu,mem,disk usage,server type,cpu type etc of […]

The post How to create host configuration report using ansible-cmdb appeared first on DBACLASS.

]]>
ansible-cmdb tool can be used to create system configuration report of your host inventory in different formats like html,csv, json,sql etc.  Let’s go through the below demonstration . Lets say you have hundreds of servers and you can want to generate a report that has server overview details like cpu,mem,disk usage,server type,cpu type etc of all your servers. In that case ansible-cmdb tool can be used to achieve that target.

Install ansible-cmdb tool:

Download link – > https://github.com/fboender/ansible-cmdb/releases

 

 


[root@DBHOST ansible-cmdb_rpm]# tar -vxzf ansible-cmdb-1.28.tar.gz
ansible-cmdb-1.28/
ansible-cmdb-1.28/.gitignore
ansible-cmdb-1.28/LICENSE
ansible-cmdb-1.28/Makefile
ansible-cmdb-1.28/README.md
ansible-cmdb-1.28/contrib/
ansible-cmdb-1.28/contrib/ansible-cmdb.man.1
ansible-cmdb-1.28/contrib/debian/
ansible-cmdb-1.28/contrib/debian/DEBIAN/
ansible-cmdb-1.28/contrib/debian/DEBIAN/control
ansible-cmdb-1.28/contrib/debian/changelog
ansible-cmdb-1.28/contrib/debian/copyright
ansible-cmdb-1.28/contrib/release_Makefile
ansible-cmdb-1.28/contrib/screenshot-detail.png
ansible-cmdb-1.28/contrib/screenshot-overview.png
ansible-cmdb-1.28/docs/
ansible-cmdb-1.28/docs/dev.md
ansible-cmdb-1.28/docs/faq.md
ansible-cmdb-1.28/docs/index.md
ansible-cmdb-1.28/docs/installation.md
ansible-cmdb-1.28/docs/usage.md
ansible-cmdb-1.28/example/
ansible-cmdb-1.28/example/ansible.cfg
ansible-cmdb-1.28/example/dyninv_test.py
ansible-cmdb-1.28/example/dyninv_vbox.py
.
.
.
.
ansible-cmdb-1.28/test/f_inventory/mixeddir/dyninv.py
ansible-cmdb-1.28/test/f_inventory/mixeddir/hosts
ansible-cmdb-1.28/test/f_inventory/out/
ansible-cmdb-1.28/test/f_inventory/out/db.dev.local
ansible-cmdb-1.28/test/test.py
ansible-cmdb-1.28/test/test.sh


[root@DBHOST ansible-cmdb_rpm]# cd ansible-cmdb-1.28/


[root@DBHOST ansible-cmdb-1.28]# make install
umask 0022 && mkdir -p /usr/local/lib/ansible-cmdb
umask 0022 && mkdir -p /usr/local/man/man1
umask 0022 && cp -a src/* /usr/local/lib/ansible-cmdb
umask 0022 && cp -r lib/* /usr/local/lib/ansible-cmdb
umask 0022 && cp LICENSE /usr/local/lib/ansible-cmdb
umask 0022 && cp README.md /usr/local/lib/ansible-cmdb
umask 0022 && gzip -9 -c contrib/ansible-cmdb.man.1 > /usr/local/man/man1/ansible-cmdb.man.1.gz
umask 0022 && ln -s /usr/local/lib/ansible-cmdb/ansible-cmdb /usr/local/bin/ansible-cmdb

[root@DBHOST ansible-cmdb-1.28]# which ansible-cmdb
/usr/local/bin/ansible-cmdb


Create inventory file


cat /home/ansible/ansible-scipts/dbaclass_inventory

linux_host1 ansible_host=182.34.86.60 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host2 ansible_host=182.34.86.61 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host3 ansible_host=182.34.86.62 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host4 ansible_host=182.34.86.63 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host5 ansible_host=182.34.86.64 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host6 ansible_host=182.34.86.65 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host7 ansible_host=182.34.86.40 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host8 ansible_host=182.34.86.41 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host9 ansible_host=182.34.86.42 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host10 ansible_host=182.34.86.43 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host11 ansible_host=182.34.86.44 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host12 ansible_host=182.34.86.45 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host13 ansible_host=182.34.86.46 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host14 ansible_host=182.34.86.47 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host15 ansible_host=182.34.86.48 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123
linux_host16 ansible_host=182.35.36.114 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbaclass@123

Generate report:

Before generating report, first step is to collect the facts gathering details of all hosts.

mkdir out 

ansible -i /home/ansible/ansible-scipts/dbaclass_inventory  -m setup --tree out/ all

this command will create unique file for each host in out directory .

ansible-cmdb provides different templates to generate report. Most popular and default one is the html template.

  1. Generate html report:


root# ansible-cmdb -i /home/ansible/ansible-scipts/dbaclass_inventory -t html_fancy out/ > dbaclass_inventory.html

 

Now view the dbaclass_inventory.html report in your browser. You can select different columns and view the updated reports.

 

 

 

 

 

 

 

       3. Generate csv report:

You can generate the inventory overview report in csv format also.

 [ansible@DBHOST ansible-scipts]$ ansible-cmdb  -i /home/ansible/ansible-scipts/dbaclass_inventory   -t csv out > hostinv.csv

 

 

       3. Generate text output on command prompt:


[ansible@DBHOST ansible-scipts]$  ansible-cmdb  -i /home/ansible-scipts/dbaclass_inventory  -t txt_table --columns ip,os,mem,cpus,memfree,memused out/

OS            IP              Mem   MemFree  MemUsed  CPUs
------------  --------------  ----  -------  -------  ----
RedHat 6.10   182.34.86.41    32g   29g      3g       1
RedHat 6.10   182.34.86.42    64g   61g      3g       2
RedHat 7.9    182.34.86.65    64g   60g      4g       2
RedHat 7.7    182.34.86.40    161g  45g      116g     4
RedHat 7.9    182.34.86.63    64g   18g      46g      2
RedHat 7.9    182.34.86.64    64g   59g      6g       2
RedHat 6.10   182.34.86.61    32g   29g      3g       1
RedHat 7.9    182.34.86.62    64g   30g      34g      2
RedHat 6.10   182.34.86.60    161g  27g      135g     4
RedHat 6.10   182.35.62.68    32g   26g      6g       2
RedHat 6.10   182.35.62.67    32g   23g      9g       2

      4. Generate a sql file:

You can generate a sql file, which can be run on any sql database to create a host table and load the inventory data.

[ansible@DBHOST ansible-scipts]$  ansible-cmdb  -i /home/ansible-scipts/dbaclass_inventory  -t sql out > hostinv.sql

cat hostinv.sql

DROP TABLE IF EXISTS hosts;
CREATE TABLE hosts (
    name VARCHAR(255),
    fqdn VARCHAR(255),
    main_ip VARCHAR(15),
    os_name VARCHAR(80),
    os_version VARCHAR(40),
    system VARCHAR(40),
    kernel VARCHAR(40),
    arch_hardware VARCHAR(12),
    arch_userspace VARCHAR(12),
    virt_type VARCHAR(20),
    virt_role VARCHAR(20),
    cpu_type VARCHAR(60),
    vcpus INT,
    ram FLOAT,
    disk_total FLOAT,
    disk_free FLOAT
);

    INSERT INTO hosts (
        name,
        fqdn,
        main_ip,
        os_name,
        os_version,
        system,
        kernel,
        arch_hardware,
        arch_userspace,
        virt_type,
        virt_role,
        cpu_type,
        vcpus,
        ram,
        disk_total,
        disk_free
    ) VALUES (
        "linux_host8",
.
.
.
.
.

 

NOTE – > For more information regarding ansible-cmd visit https://ansible-cmdb.readthedocs.io/en/latest/usage/

The post How to create host configuration report using ansible-cmdb appeared first on DBACLASS.

]]>
https://dbaclass.com/article/how-to-create-host-configuration-report-using-ansible-cmdb/feed/ 2
How to encrypt ansible inventory file using ansible-vault https://dbaclass.com/article/how-to-encrypt-ansible-inventory-file-using-ansible-vault/ https://dbaclass.com/article/how-to-encrypt-ansible-inventory-file-using-ansible-vault/#respond Tue, 27 Oct 2020 15:55:17 +0000 https://dbaclass.com/?post_type=article&p=6239 If you have hardcoded your host credentials in your inventory file, then it is strongly advised to encrypt that file with proper passcode. In this example, we will see how to do that. 1. Check the inventory file: $ cat preprod_hosts linux_host1 ansible_host=192.289.86.60 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbatest@123 linux_host2 ansible_host=192.289.86.61 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbatest@123 linux_host3 ansible_host=192.289.86.62 ansible_connection=ssh ansible_user=root […]

The post How to encrypt ansible inventory file using ansible-vault appeared first on DBACLASS.

]]>
If you have hardcoded your host credentials in your inventory file, then it is strongly advised to encrypt that file with proper passcode.

In this example, we will see how to do that.

1. Check the inventory file:


$ cat preprod_hosts
linux_host1 ansible_host=192.289.86.60 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbatest@123
linux_host2 ansible_host=192.289.86.61 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbatest@123
linux_host3 ansible_host=192.289.86.62 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbatest@123

2. Now encrypt the inventory file ( preprod_hosts)


$ ansible-vault encrypt preprod_hosts
New Vault password:                  --- >>> enter your password 
Confirm New Vault password:
Encryption successful

3. Check whether file has been encrypted or not.


$ cat preprod_hosts
$ANSIBLE_VAULT;1.1;AES256
63343930303032363031346230663937323731633463356662363430303735653734383131306233
6635623765633634343730326638623737396462383233340a616565376139316664613061313831
34373864336461363134313831653437393035653530333064383735353834386534373639373534
3838623933323032380a373536653935363535343762616535653638656636613739636437633638
66336433633532646437366161356537616536666630343362363132353331656464636266333136
61626264343463623963636239616638323733646366313561623765376663373664613135353639
61613234346633366231363432313365366165343261363137653531373230313261633233623263
30633062643861633433383937363034356336646362626632643332623538326630383335383931
32396566353837633535373861633761356239353034306238356634343761633437366263653430
61643565333838303464366535396665386563333166353236653735356633393138623834633937
33626564333733396537623033343636373035343537356466393935643462363064656162303038
33383631646664396630323463613966333062623831393135646138306631666234346335323039
35656465393632363537343136643562653230626366393938313631346633376432316533366638
36343933636266343633373839396261323664646538633463336134663632333134363962376532
63393536646636303235313132623539323531363532306462373538663433313331643135393537
65633266666563613538636130343238663136356664666633343835323163333733336166626362
62323834393461313735316231623663646132623938633264386236323039356134363462343834
65383131376366323366363763313562666166323235366233353061613933663038393537636133
62356538613132303461373063386638616463643262636564373062376639313366343931636261
34386137373936646535373562303139346433323134613039653739376362623530653038346337
3664

4. The same can be decrypted using below syntax:


$ ansible-vault decrypt preprod_hosts
Vault password:
Decryption successful

$cat preprod_hosts
linux_host1 ansible_host=192.289.86.60 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbatest@123
linux_host2 ansible_host=192.289.86.61 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbatest@123
linux_host3 ansible_host=192.289.86.62 ansible_connection=ssh ansible_user=root ansible_ssh_pass=dbatest@123



The post How to encrypt ansible inventory file using ansible-vault appeared first on DBACLASS.

]]>
https://dbaclass.com/article/how-to-encrypt-ansible-inventory-file-using-ansible-vault/feed/ 0
Ansible script to run script on remote server and fetch the output https://dbaclass.com/article/ansible-script-run-script-remote-server-fetch-output/ https://dbaclass.com/article/ansible-script-run-script-remote-server-fetch-output/#comments Sat, 15 Aug 2020 17:48:37 +0000 https://dbaclass.com/?post_type=article&p=6020 REQUIREMENT: Write an ansible script ,that will 1. Copy the script collect_info.sh to all the hosts. 1. Run the shell script ( collect_info.sh ) , against the hosts mentioned in host file. 2. Script will be run as root user. 3. The output file of the script ( will be like collect*txt) need to be […]

The post Ansible script to run script on remote server and fetch the output appeared first on DBACLASS.

]]>
REQUIREMENT:

Write an ansible script ,that will
1. Copy the script collect_info.sh to all the hosts.
1. Run the shell script ( collect_info.sh ) , against the hosts mentioned in host file.
2. Script will be run as root user.
3. The output file of the script ( will be like collect*txt) need to be copied to local host.

Below is the ansible playbook script:

cat collect_info.yml

– hosts: all
  strategy: free
  user: bvunix
  become: yes
  become_method: sudo
  become_user: root
  tasks:
    – name: Copy script collect_audit.sh
      copy: src=collect_audit.sh dest=/home/bvunix mode=0777
    – name: Run script for audit
      command: sh /home/bvunix/collect_audit.sh
    – name: find the output file
      shell: (cd /home/bvunix; find collect*.txt)
      register: files_to_copy
    – debug:
        var: files_to_copy
    – name: Fetch the file from remote to local
      fetch: src=/home/bvunix/{{ item }} dest=/home/bvunix/ mode=0777 flat=yes
      with_items: “{{ files_to_copy.stdout_lines }}”

– Execute the playbook

Ansible-playbook collect_info.yml -f 10

 

-HOSTFILE :

— If password less ssh connectivity is established, then use the below simple hostfile

172.20.192.1
172.20.192.2
172.20.192.3

— If no passwordless ssh setup is there, then hardcode the credentials as below:

linux1 ansible_host=172.20.192.1 ansible_connection=ssh ansible_user=bvunix ansible_ssh_pass=classic123
linux2 ansible_host=172.20.192.3 ansible_connection=ssh ansible_user=bvunix ansible_ssh_pass=classic123
linux3 ansible_host=172.20.192.3 ansible_connection=ssh ansible_user=bvunix ansible_ssh_pass=classic123

 

In the later tutorial,  we will explain how to use ansible-vault to encrypt the host file.

The post Ansible script to run script on remote server and fetch the output appeared first on DBACLASS.

]]>
https://dbaclass.com/article/ansible-script-run-script-remote-server-fetch-output/feed/ 3
how to Print execution time of tasks in ansible https://dbaclass.com/article/print-execution-time-tasks-ansible/ https://dbaclass.com/article/print-execution-time-tasks-ansible/#respond Mon, 01 Jun 2020 17:34:43 +0000 https://dbaclass.com/?post_type=article&p=5610 Suppose you are running a ansible playbook with multiple tasks and want to print execution time of each task, then do the below changes. Lets see the below sample playbook execution . In this ouput we dont know how much it took for each task execution. [root@ans_scripts]# ansible-playbook playbook_copyfile_multi.yml -i /etc/ansible/inventory.txt PLAY [copy files to […]

The post how to Print execution time of tasks in ansible appeared first on DBACLASS.

]]>
Suppose you are running a ansible playbook with multiple tasks and want to print execution time of each task, then do the below changes.

Lets see the below sample playbook execution . In this ouput we dont know how much it took for each task execution.

[root@ans_scripts]#  ansible-playbook playbook_copyfile_multi.yml -i /etc/ansible/inventory.txt
 
PLAY [copy files to test servers] ***********************************************************************************************************************************************
 
TASK [Gathering Facts] **********************************************************************************************************************************************************
ok: [db_server2]
ok: [db_server1]
 
TASK [Ansible copy files to remote machine] *************************************************************************************************************************************
changed: [db_server1] => (item=test1.log)
changed: [db_server2] => (item=test1.log)
ok: [db_server1] => (item=test2.log)
ok: [db_server2] => (item=test2.log)
 
PLAY RECAP **********************************************************************************************************************************************************************
db_server1                 : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
db_server2                 : ok=2    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

For enabling the changes, we need to set the callback_whitelist = profile_tasks inside ansible.cfg file.

 

[root@ansible]# cat /etc/ansible/ansible.cfg |grep callback_whitelist
callback_whitelist = profile_tasks

 

Now run the same playbook in ansible again.

 

[root@ans_scripts]#  ansible-playbook playbook_copyfile_multi.yml -i /etc/ansible/inventory.txt
 
PLAY [copy files to test servers] ***********************************************************************************************************************************************
 
TASK [Gathering Facts] **********************************************************************************************************************************************************
Sunday 31 May 2020  08:27:31 +0300 (0:00:00.047)       0:00:00.047 ************
ok: [db_server1]
ok: [db_server2]
 
TASK [Ansible copy files to remote machine] *************************************************************************************************************************************
Sunday 31 May 2020  08:27:35 +0300 (0:00:04.027)       0:00:04.074 ************
ok: [db_server1] => (item=test1.log)
ok: [db_server2] => (item=test1.log)
ok: [db_server1] => (item=test2.log)
ok: [db_server2] => (item=test2.log)
 
PLAY RECAP **********************************************************************************************************************************************************************
db_server1                 : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
db_server2                 : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
 
Sunday 31 May 2020  08:27:38 +0300 (0:00:03.103)       0:00:07.178 ************
===============================================================================
Gathering Facts ---------------------------------------------------------------------------------------------------------------------------------------------------------- 4.03s
Ansible copy files to remote machine ------------------------------------------------------------------------------------------------------------------------------------- 3.10s

The post how to Print execution time of tasks in ansible appeared first on DBACLASS.

]]>
https://dbaclass.com/article/print-execution-time-tasks-ansible/feed/ 0