Skip to content
Snippets Groups Projects
Commit 1866d1b5 authored by Shahaan Ayyub's avatar Shahaan Ayyub
Browse files

Merge pull request #139 from shahaan/master

centos7Base and dynamicInventory
parents a8bba05b bb0841d4
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env python
import sys, os, string, socket, re
import shlex, multiprocessing, time, shutil, json
import novaclient.v1_1.client as nvclient
from novaclient import client as nvclient
import novaclient.exceptions as nvexceptions
import keystoneclient.v2_0.client as ksclient
from joblib import Parallel, delayed
from multiprocessing import Process, Manager, Pool
from libnmap.process import NmapProcess
from libnmap.parser import NmapParser, NmapParserException
def gatherInfo(tenantName, tenantID, userName, passwd, authUrl, inventory):
## Fetch the Nova Object
projectName = os.path.basename(sys.argv[0])
nc = nvclient.Client( auth_url=authUrl,
......@@ -16,24 +17,23 @@ def gatherInfo(tenantName, tenantID, userName, passwd, authUrl, inventory):
api_key=passwd,
project_id=tenantName,
tenant_id=tenantID,
service_type="compute"
version="2"
)
for server in nc.servers.list():
if server.metadata and \
'ansible_host_groups' in server.metadata and \
server.metadata['project_name'] == projectName.strip():
'project_name' in server.metadata:
if server.metadata['project_name'].strip() != projectName.strip(): continue
unwantedChars = """][")("""
rgx = re.compile('[%s]' % unwantedChars)
ansible_groups = rgx.sub('', server.metadata['ansible_host_groups']).split(',')
hostname = socket.gethostbyaddr(server.networks.values()[0][0])[0]
closed=True
while closed:
hostSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
if not hostSocket.connect_ex((hostname, 22)):
closed = False
break
time.sleep(5)
hostSocket.close()
novaVolumes = nc.volumes.get_server_volumes(server.id)
# Let's do some port scanning using nmap
nmproc = NmapProcess(hostname, "-p 22 -sV -Pn")
rc = nmproc.run()
if rc != 0: continue
parsed = NmapParser.parse(nmproc.stdout)
# Set Ansible Host Group
for group in ansible_groups:
groupName = group.strip()
......@@ -43,11 +43,12 @@ def gatherInfo(tenantName, tenantID, userName, passwd, authUrl, inventory):
for key, value in server.metadata.iteritems():
if key not in ('project_name','ansible_host_groups'):
inventory['_meta']['hostvars'][hostname] = { key:value }
if novaVolumes:
inventory['_meta']['hostvars'][hostname]['volumeList'] = [ volume.id for volume in novaVolumes ]
inventory['_meta']['hostvars'][hostname]['status'] = parsed.hosts[0].status
else:
continue
#print inventory
#inventoryList.append(inventory)
#print json.dumps(inventory)
if __name__ == "__main__":
inventory = {}
......
---
-
name: Removing the RDO repository
file: path=/etc/yum.repos.d/rdo-release.repo state=absent
sudo: true
-
name: Installing Base Packages
yum: name={{ item }} state=present
with_items:
- environment-modules-3.2.10-8.el7.x86_64
- epel-release-7-5.noarch
- yum-utils
- deltarpm-3.6-3.el7.x86_64
- yum-plugin-versionlock
-
name: Enable epel
command: yum-config-manager --enable epel
-
name: Template the Modules path
template: src=.modulespath.j2 dest=/usr/share/Modules/init/.modulespath owner=root mode=0644
-
name: Installing Core packages
yum: name="{{ item.software }}-{{ item.version }}.{{ item.arch }}" state=present
with_items: package_list
sudo: true
-
name: Performing version lock on the packages
shell: yum versionlock \*
sudo: true
---
- include: installBasePackages.yml
---
-
name: Mount the swStack Persistent Volume
# Module version 3.2.10
# init/.modulespath. Generated from .modulespath.in by configure.
#
# Modulepath initial setup
# ========================
#
# This file defines the initial setup for the module files search path.
# Comments may be added anywhere, which begin on # and continue until the
# end of the line
# Each line containing a single path will be added to the MODULEPATH
# environment variable. You may add as many as you want - just
# limited by the maximum variable size of your shell.
#
# # location of version files
#/usr/share/Modules/$MODULE_VERSION/modulefiles # Module pkg modulefiles (if versioning)
#/usr/share/Modules/modulefiles # Module pkg modulefiles (if no versioning)
/usr/local/Modules/modulefiles
#/etc/modulefiles # General module files
#/usr/share/Modules/your_contribs # Edit for your requirements
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment