diff --git a/docsite/latest/rst/contrib.rst b/docsite/latest/rst/contrib.rst index ea8a406003a..591579015ba 100644 --- a/docsite/latest/rst/contrib.rst +++ b/docsite/latest/rst/contrib.rst @@ -23,6 +23,7 @@ though a few may remain outside of core depending on use cases and implementatio - `zypper (bash module example) `_ - jp\_mens - `additional provisioning-related modules `_ - jhoekx and dagwieers - `dynamic dns updates `_ - jp\_mens +- `apk-tools `_ - Bartłomiej Piotrowski All python modules (especially all submitted to core) should use the common "AnsibleModule" class to dramatically reduce the amount of boilerplate code required. diff --git a/library/files/lineinfile b/library/files/lineinfile index 7aac8e81c35..ae4e0c7b458 100644 --- a/library/files/lineinfile +++ b/library/files/lineinfile @@ -118,7 +118,7 @@ EXAMPLES = r""" lineinfile: dest=/etc/sudoers state=absent regexp="^%wheel" - lineinfile: dest=/etc/host regexp='^127\.0\.0\.1' line='127.0.0.1 localhost' owner=root group=root mode=0644 + lineinfile: dest=/etc/hosts regexp='^127\.0\.0\.1' line='127.0.0.1 localhost' owner=root group=root mode=0644 lineinfile: dest=/etc/httpd/conf/httpd.conf regexp="^Listen " insertafter="^#Listen " line="Listen 8080" diff --git a/library/notification/irc b/library/notification/irc index 84a0a71c009..4dfd9b4fa7c 100644 --- a/library/notification/irc +++ b/library/notification/irc @@ -76,6 +76,7 @@ local_action: irc port=6669 # IRC module support methods. # +from time import sleep import socket def send_msg(channel, msg, server='localhost', port='6667', @@ -101,10 +102,13 @@ def send_msg(channel, msg, server='localhost', port='6667', irc.connect( ( server, int(port) ) ) irc.send( 'NICK %s\r\n' % nick ) irc.send( 'USER %s %s %s :ansible IRC\r\n' % (nick, nick, nick)) - irc.send( 'JOIN #%s\r\n' % channel ) + time.sleep(1) + irc.send( 'JOIN %s\r\n' % channel ) irc.send( 'PRIVMSG %s :%s\r\n' % (channel, message)) + time.sleep(1) irc.send( 'PART %s\r\n' % channel) irc.send( 'QUIT\r\n' ) + time.sleep(1) irc.close() # =========================================== diff --git a/library/system/setup b/library/system/setup index 6c075c032e8..274fb469ee9 100644 --- a/library/system/setup +++ b/library/system/setup @@ -117,6 +117,7 @@ class Facts(object): { 'path' : '/opt/local/bin/port', 'name' : 'macports' }, { 'path' : '/sbin/apk', 'name' : 'apk' }, { 'path' : '/usr/sbin/pkg', 'name' : 'pkgng' }, + { 'path' : '/usr/sbin/swlist', 'name' : 'SD-UX' }, ] def __init__(self): @@ -182,7 +183,7 @@ class Facts(object): Archlinux = 'Archlinux', Mandriva = 'Mandrake', Mandrake = 'Mandrake', Solaris = 'Solaris', Nexenta = 'Solaris', OmniOS = 'Solaris', OpenIndiana = 'Solaris', SmartOS = 'Solaris', AIX = 'AIX', Alpine = 'Alpine', MacOSX = 'Darwin', - FreeBSD = 'FreeBSD' + FreeBSD = 'FreeBSD', HPUX = 'HP-UX' ) if self.facts['system'] == 'AIX': @@ -191,6 +192,13 @@ class Facts(object): data = out.split('.') self.facts['distribution_version'] = data[0] self.facts['distribution_release'] = data[1] + elif self.facts['system'] == 'HP-UX': + self.facts['distribution'] = 'HP-UX' + rc, out, err = module.run_command("/usr/sbin/swlist |egrep 'HPUX.*OE.*[AB].[0-9]+\.[0-9]+'") + data = re.search('HPUX.*OE.*([AB].[0-9]+\.[0-9]+)\.([0-9]+).*', out) + if data: + self.facts['distribution_version'] = data.groups()[0] + self.facts['distribution_release'] = data.groups()[1] elif self.facts['system'] == 'Darwin': self.facts['distribution'] = 'MacOSX' rc, out, err = module.run_command("/usr/bin/sw_vers -productVersion") @@ -1036,6 +1044,103 @@ class AIX(Hardware): data = out.split() self.facts['firmware_version'] = data[1].strip('IBM,') +class HPUX(Hardware): + """ + HP-UX-specifig subclass of Hardware. Defines memory and CPU facts: + - memfree_mb + - memtotal_mb + - swapfree_mb + - swaptotal_mb + - processor + - processor_cores + - processor_count + - model + - firmware + """ + platform = 'HP-UX' + def __init__(self): + Hardware.__init__(self) + + def populate(self): + self.get_cpu_facts() + self.get_memory_facts() + self.get_hw_facts() + return self.facts + + def get_cpu_facts(self): + if self.facts['architecture'] == '9000/800': + rc, out, err = module.run_command("ioscan -FkCprocessor|wc -l") + self.facts['processor_count'] = int(out.strip()) + #Working with machinfo mess + elif self.facts['architecture'] == 'ia64': + if self.facts['distribution_version'] == "B.11.23": + rc, out, err = module.run_command("/usr/contrib/bin/machinfo |grep 'Number of CPUs'") + self.facts['processor_count'] = int(out.strip().split('=')[1]) + rc, out, err = module.run_command("/usr/contrib/bin/machinfo |grep 'processor family'") + self.facts['processor'] = re.search('.*(Intel.*)', out).groups()[0].strip() + rc, out, err = module.run_command("ioscan -FkCprocessor|wc -l") + self.facts['processor_cores'] = int(out.strip()) + if self.facts['distribution_version'] == "B.11.31": + #if machinfo return cores strings release B.11.31 > 1204 + rc, out, err = module.run_command("/usr/contrib/bin/machinfo |grep core|wc -l") + if out.strip()== '0': + rc, out, err = module.run_command("/usr/contrib/bin/machinfo |grep Intel") + self.facts['processor_count'] = int(out.strip().split(" ")[0]) + #If hyperthreading is active divide cores by 2 + rc, out, err = module.run_command("/usr/sbin/psrset |grep LCPU") + data = re.sub(' +',' ',out).strip().split(' ') + if len(data) == 1: + hyperthreading = 'OFF' + else: + hyperthreading = data[1] + rc, out, err = module.run_command("/usr/contrib/bin/machinfo |grep logical") + data = out.strip().split(" ") + if hyperthreading == 'ON': + self.facts['processor_cores'] = int(data[0])/2 + else: + if len(data) == 1: + self.facts['processor_cores'] = self.facts['processor_count'] + else: + self.facts['processor_cores'] = int(data[0]) + rc, out, err = module.run_command("/usr/contrib/bin/machinfo |grep Intel |cut -d' ' -f4-") + self.facts['processor'] = out.strip() + else: + rc, out, err = module.run_command("/usr/contrib/bin/machinfo |egrep 'socket[s]?$' | tail -1"); + self.facts['processor_count'] = int(out.strip().split(" ")[0]) + rc, out, err = module.run_command("/usr/contrib/bin/machinfo |grep -e '[0-9] core' |tail -1") + self.facts['processor_cores'] = int(out.strip().split(" ")[0]) + rc, out, err = module.run_command("/usr/contrib/bin/machinfo |grep Intel") + self.facts['processor'] = out.strip() + + def get_memory_facts(self): + pagesize = 4096 + rc, out, err = module.run_command("/usr/bin/vmstat|tail -1") + data = int(re.sub(' +',' ',out).split(' ')[5].strip()) + self.facts['memfree_mb'] = pagesize * data / 1024 / 1024 + if self.facts['architecture'] == '9000/800': + rc, out, err = module.run_command("grep Physical /var/adm/syslog/syslog.log") + data = re.search('.*Physical: ([0-9]*) Kbytes.*',out).groups()[0].strip() + self.facts['memtotal_mb'] = int(data) / 1024 + else: + rc, out, err = module.run_command("/usr/contrib/bin/machinfo |grep Memory") + data = re.search('Memory[\ :=]*([0-9]*).*MB.*',out).groups()[0].strip() + self.facts['memtotal_mb'] = int(data) + rc, out, err = module.run_command("/usr/sbin/swapinfo -m -d -f -q") + self.facts['swaptotal_mb'] = int(out.strip()) + rc, out, err = module.run_command("/usr/sbin/swapinfo -m -d -f |egrep '^dev|^fs'") + swap = 0 + for line in out.strip().split('\n'): + swap += int(re.sub(' +',' ',line).split(' ')[3].strip()) + self.facts['swapfree_mb'] = swap + + def get_hw_facts(self): + rc, out, err = module.run_command("model") + self.facts['model'] = out.strip() + if self.facts['architecture'] == 'ia64': + rc, out, err = module.run_command("/usr/contrib/bin/machinfo |grep -i 'Firmware revision' |grep -v BMC") + self.facts['firmware_version'] = out.split(':')[1].strip() + + class Darwin(Hardware): """ Darwin-specific subclass of Hardware. Defines memory and CPU facts: @@ -1608,9 +1713,9 @@ class SunOSNetwork(GenericBsdIfconfigNetwork, Network): else: current_if = interfaces[device] flags = self.get_options(words[1]) - if 'IPv4' in flags: + if 'IPv4' in flags: v = 'ipv4' - if 'IPv6' in flags: + if 'IPv6' in flags: v = 'ipv6' current_if[v].append({'flags': flags, 'mtu': words[3]}) current_if['macaddress'] = 'unknown' # will be overwritten later