Commit ce5f3dd1 by Michael DeHaan

Port the file module over to the new common code infrastructure + cleanup some…

Port the file module over to the new common code infrastructure + cleanup some redundant imports since the module code already imports those things.
parent 8e60ad98
......@@ -65,7 +65,3 @@ def main():
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main()
#!/usr/bin/python
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import sys
try:
import json
except ImportError:
import simplejson as json
print >>sys.stderr, "THIS IS A TEST FAILURE"
print json.dumps({
"failed" : True,
"msg" : "this module always fails"
})
......@@ -19,9 +19,7 @@
#
# see examples/playbooks/get_url.yml
import os
import shutil
import syslog
import datetime
import tempfile
......@@ -188,5 +186,4 @@ def main():
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main()
......@@ -22,9 +22,7 @@
# tag. Latest is not supported, you should not be doing
# that. Contribs welcome! -- MPD
import os
import re
import subprocess
def get_version(dest):
''' samples the version of the git repo '''
......
......@@ -17,9 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import os
import grp
import subprocess
def get_bin_path(module, arg):
if os.path.exists('/usr/sbin/%s' % arg):
......
......@@ -19,13 +19,16 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#mount module - mount fs and define in fstab
#usage:
# mount name=mountpoint, src=device_to_be_mounted fstype=fstype opts=mount_opts, dump=0 passno=0 state=[present|absent|mounted|unmounted]
# absent == remove from fstab and unmounted
# present == add to fstab, do not change mount state
# mounted == add to fstab if not there and make sure it is mounted
# unmounted == do not change fstab state, but unmount
# mount module - mount fs and define in fstab
# usage:
#
# mount name=mountpoint, src=device_to_be_mounted fstype=fstype
# opts=mount_opts, dump=0 passno=0 state=[present|absent|mounted|unmounted]
#
# absent == remove from fstab and unmounted
# present == add to fstab, do not change mount state
# mounted == add to fstab if not there and make sure it is mounted
# unmounted == do not change fstab state, but unmount
def write_fstab(lines, dest):
......@@ -37,14 +40,15 @@ def write_fstab(lines, dest):
fs_w.close()
def set_mount(**kwargs):
"set/change a mount point location in fstab"
""" set/change a mount point location in fstab """
# kwargs: name, src, fstype, opts, dump, passno, state, fstab=/etc/fstab
args = {
'opts': 'defaults',
'dump': '0',
'passno': '0',
'fstab': '/etc/fstab'
}
args = dict(
opts = 'defaults',
dump = '0',
passno = '0',
fstab = '/etc/fstab'
)
args.update(kwargs)
new_line = '%(src)s %(name)s %(fstype)s %(opts)s %(dump)s %(passno)s\n'
......@@ -84,7 +88,6 @@ def set_mount(**kwargs):
else:
to_write.append(line)
if not exists:
to_write.append(new_line % args)
changed = True
......@@ -96,14 +99,15 @@ def set_mount(**kwargs):
def unset_mount(**kwargs):
"remove a mount point from fstab"
""" remove a mount point from fstab """
# kwargs: name, src, fstype, opts, dump, passno, state, fstab=/etc/fstab
args = {
'opts': 'default',
'dump': '0',
'passno': '0',
'fstab': '/etc/fstab'
}
args = dict(
opts = 'default',
dump = '0',
passno = '0',
fstab = '/etc/fstab'
)
args.update(kwargs)
to_write = []
......@@ -138,7 +142,8 @@ def unset_mount(**kwargs):
def mount(**kwargs):
"mount up a path or remount if needed"
""" mount up a path or remount if needed """
name = kwargs['name']
if os.path.ismount(name):
cmd = ['/bin/mount', '-o', 'remount', name]
......@@ -153,7 +158,8 @@ def mount(**kwargs):
return call.returncode, out+err
def umount(**kwargs):
"unmount a path"
""" unmount a path """
name = kwargs['name']
cmd = ['/bin/umount', name]
......@@ -165,6 +171,7 @@ def umount(**kwargs):
return call.returncode, out+err
def main():
module = AnsibleModule(
argument_spec = dict(
state = dict(required=True, choices=['present', 'absent', 'mounted', 'unmounted']),
......@@ -194,7 +201,6 @@ def main():
if module.params['fstab'] is not None:
args['fstab'] = module.params['fstab']
# absent == remove from fstab and unmounted
# unmounted == do not change fstab state, but unmount
# present == add to fstab, do not change mount state
......@@ -218,7 +224,6 @@ def main():
module.exit_json(changed=changed, **args)
if state == 'unmounted':
if os.path.ismount(name):
res,msg = umount(**args)
......@@ -228,8 +233,6 @@ def main():
module.exit_json(changed=changed, **args)
if state in ['mounted', 'present']:
name, changed = set_mount(**args)
if state == 'mounted':
......@@ -258,5 +261,4 @@ def main():
# this is magic, see lib/ansible/module_common.py
#<<INCLUDE_ANSIBLE_MODULE_COMMON>>
main()
......@@ -18,21 +18,16 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
import subprocess
def get_facter_data():
p = subprocess.Popen(["/usr/bin/env", "ohai"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(out, err) = p.communicate()
rc = p.returncode
return rc, out, err
def main():
module = AnsibleModule(
argument_spec = dict()
)
rc, out, err = get_facter_data()
if rc != 0:
module.fail_json(msg=err)
......
......@@ -17,8 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import base64
def main():
module = AnsibleModule(
argument_spec = dict()
......
......@@ -26,19 +26,16 @@ else:
# PostgreSQL module specific support methods.
#
def db_exists(cursor, db):
query = "SELECT * FROM pg_database WHERE datname=%(db)s"
cursor.execute(query, {'db': db})
return cursor.rowcount == 1
def db_delete(cursor, db):
query = "DROP DATABASE %s" % db
cursor.execute(query)
return True
def db_create(cursor, db):
query = "CREATE DATABASE %s" % db
cursor.execute(query)
......@@ -48,7 +45,6 @@ def db_create(cursor, db):
# Module execution.
#
def main():
module = AnsibleModule(
argument_spec=dict(
......
......@@ -20,14 +20,10 @@
import array
import fcntl
import glob
import sys
import os
import platform
import re
import socket
import struct
import subprocess
import traceback
try:
import selinux
......
......@@ -17,8 +17,6 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import base64
def main():
module = AnsibleModule(
argument_spec = dict(
......
......@@ -17,10 +17,8 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
import os
import pwd
import grp
import subprocess
try:
import spwd
HAVE_SPWD=True
......
......@@ -17,11 +17,6 @@ VIRT_FAILED = 1
VIRT_SUCCESS = 0
VIRT_UNAVAILABLE=2
# other modules
import os
import sys
import subprocess
try:
import libvirt
except ImportError:
......
......@@ -18,7 +18,6 @@
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
import yum
import datetime
import traceback
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment