Skip to main content

Collect ansible Inventory from directories

Hello

Thanks for visiting RvKmR.blogspot.in

In this blog post, I am explaining about ansible inventory.

While working with ansible we need to provide inventory to ansible commands.

We may have ansible inventory structure as like below. There can be some tasks that you wish to perform on all of the inventory. But it is difficult to collect or merge these into one file.

Lets do it ...

level1/
├── level2-0
│   └── inventory
│       ├── server01
│       ├── server02
│       ├── server03
│       ├── server04
│       ├── server05
│       ├── server06
│       ├── server07
│       ├── server08
│       ├── server09
│       └── server10
├── level2-1
│   └── inventory
│       ├── server11
│       ├── server12
│       ├── server13
│       ├── server14
│       ├── server15
│       ├── server16
│       ├── server17
│       ├── server18
│       ├── server19
│       └── server20
└── level2-2
    └── inventory
        ├── server21
        ├── server22
        ├── server23
        ├── server24
        ├── server25
        ├── server26
        ├── server27
        ├── server28
        ├── server29
        └── server30

But we may need it in like all={[file1,file2......file30]}
So for that we can do that it like as below. Your inventory will be in host.ini

echo "all={[" >> host.ini;
ls -l level1/*/inventory/ | awk '{print $9","}' | grep -v '^$' | grep -v '^,'>> host.ini;
echo "]}" >> host.ini









Comments

Popular posts from this blog

Reset Multiple Linux server Password

Hello, Thanks for visiting RvKmR.blogspot.in . In this blog, I am going to explain about my script “Reset multiple Linux server password” written in bash. To understand this script you must be familiar with Bash scripting and Linux environment. Q   :  I have 100 's Linux server, I need to reset these Linux server password on weekly.  I know procedure to reset password of single server i.e. Login in to target server and reset password with utility “passwd”.  But here is issue : What if I have 100 's of server ?  it is not efficient way to login to each server and the reset password. Ans :     Written an bash script to automate this task. Details are mentioned below. There are some prerequisites needed before running this script. We need know targeted Linux server IP address and current password of server. Create a file “server_details”  at same location where is your main script located and write IP address and password like : "<I...

Installing Jenkins in ubuntu

Hello, Thanks for visiting RvKmR.blogspot.in In this blog post, I am explaining about installing Jenkins in the ubunut system. Ubuntu release that I am working on is as below DISTRIB_ID=Ubuntu DISTRIB_RELEASE=17.04 DISTRIB_CODENAME=zesty DISTRIB_DESCRIPTION="Ubuntu 17.04" I will explain working on Jenkins in another post, for now, we will discuss how to install Jenkins in Ubuntu system. To run Jenkins successfully we need a web server. I am familiar with nginx, so I am going with it. Jenkins by default works on 8080 port. Install Jenkins with below command  sudo apt-get install nginx Jenkins is written in Java, so we need Java to be installed on our system. Adding repo to install jdk sudo add-apt-repository ppa : openjdk -r/ ppa sudo apt-get update Install jdk now. sudo apt-get install openjdk -8- jdk Add Jenkins key and update source list to install Jenkins. wget https://jenkins-ci.org/debian/jenkins-ci.org.key sudo apt-key add jenki...

IT Infrastructure Monitoring

Hello, Thanks for visiting RvKmR.blogspot.in IT Infrastructure monitoring its not just words, it means a lot in the information technology world. I expect an IT professional knows what it means. In a simple word, I can say Compute, Application, and network, etc. OK, let's start why we need IT infrastructure monitoring. Monitoring IT infrastructure allows us to take preemptive action to be undertaken towards a potential problem before they affect your business. OR at least reduce time to restore your infrastructure as soon as an incident occurs. Further monitoring of IT infrastructure is divided into two categories Agent-based and agentless. An agent is a software or script installed on machines that to be monitored so that it will send information to monitoring systems. Having an agent inside the machine uses system resources, which in turn raises maintenance cost. Whereas the agentless tool is little or no impact on monitored machines as an agent is not installed on ...