mirror of https://github.com/ansible/ansible.git
Remove files added by cherry-pick from devel
parent
e6b05da55b
commit
b5ce0526bc
@ -1,145 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# (c) 2012, Franck Cuny <franck@lumberjaph.net>
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: cpanm
|
||||
short_description: Manages Perl library dependencies.
|
||||
description:
|
||||
- Manage Perl library dependencies.
|
||||
version_added: "1.0"
|
||||
options:
|
||||
name:
|
||||
description:
|
||||
- The name of the Perl library to install
|
||||
required: false
|
||||
default: null
|
||||
aliases: ["pkg"]
|
||||
from_path:
|
||||
description:
|
||||
- The local directory from where to install
|
||||
required: false
|
||||
default: null
|
||||
notest:
|
||||
description:
|
||||
- Do not run unit tests
|
||||
required: false
|
||||
default: false
|
||||
locallib:
|
||||
description:
|
||||
- Specify the install base to install modules
|
||||
required: false
|
||||
default: false
|
||||
mirror:
|
||||
description:
|
||||
- Specifies the base URL for the CPAN mirror to use
|
||||
required: false
|
||||
default: false
|
||||
examples:
|
||||
- code: "cpanm: name=Dancer"
|
||||
description: Install I(Dancer) perl package.
|
||||
- code: "cpanm: name=Dancer locallib=/srv/webapps/my_app/extlib"
|
||||
description: "Install I(Dancer) (U(http://perldancer.org/)) into the specified I(locallib)"
|
||||
- code: "cpanm: from_path=/srv/webapps/my_app/src/"
|
||||
description: Install perl dependencies from local directory.
|
||||
- code: "cpanm: name=Dancer notest=True locallib=/srv/webapps/my_app/extlib"
|
||||
description: Install I(Dancer) perl package without running the unit tests in indicated I(locallib).
|
||||
- code: "cpanm: name=Dancer mirror=http://cpan.cpantesters.org/"
|
||||
description: Install I(Dancer) perl package from a specific mirror
|
||||
notes:
|
||||
- Please note that U(http://search.cpan.org/dist/App-cpanminus/bin/cpanm, cpanm) must be installed on the remote host.
|
||||
author: Franck Cuny
|
||||
'''
|
||||
|
||||
def _is_package_installed(module, name, locallib, cpanm):
|
||||
cmd = ""
|
||||
if locallib:
|
||||
os.environ["PERL5LIB"] = "%s/lib/perl5" % locallib
|
||||
cmd = "%s perl -M%s -e '1'" % (cmd, name)
|
||||
res, stdout, stderr = module.run_command(cmd, check_rc=False)
|
||||
if res == 0:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def _build_cmd_line(name, from_path, notest, locallib, mirror, cpanm):
|
||||
# this code should use "%s" like everything else and just return early but not fixing all of it now.
|
||||
# don't copy stuff like this
|
||||
if from_path:
|
||||
cmd = "{cpanm} {path}".format(cpanm=cpanm, path=from_path)
|
||||
else:
|
||||
cmd = "{cpanm} {name}".format(cpanm=cpanm, name=name)
|
||||
|
||||
if notest is True:
|
||||
cmd = "{cmd} -n".format(cmd=cmd)
|
||||
|
||||
if locallib is not None:
|
||||
cmd = "{cmd} -l {locallib}".format(cmd=cmd, locallib=locallib)
|
||||
|
||||
if mirror is not None:
|
||||
cmd = "{cmd} --mirror {mirror}".format(cmd=cmd, mirror=mirror)
|
||||
|
||||
return cmd
|
||||
|
||||
|
||||
def main():
|
||||
arg_spec = dict(
|
||||
name=dict(default=None, required=False, aliases=['pkg']),
|
||||
from_path=dict(default=None, required=False),
|
||||
notest=dict(default=False, type='bool'),
|
||||
locallib=dict(default=None, required=False),
|
||||
mirror=dict(default=None, required=False)
|
||||
)
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec=arg_spec,
|
||||
required_one_of=[['name', 'from_path']],
|
||||
)
|
||||
|
||||
cpanm = module.get_bin_path('cpanm', True)
|
||||
name = module.params['name']
|
||||
from_path = module.params['from_path']
|
||||
notest = module.boolean(module.params.get('notest', False))
|
||||
locallib = module.params['locallib']
|
||||
mirror = module.params['mirror']
|
||||
|
||||
changed = False
|
||||
|
||||
installed = _is_package_installed(module, name, locallib, cpanm)
|
||||
|
||||
if not installed:
|
||||
out_cpanm = err_cpanm = ''
|
||||
cmd = _build_cmd_line(name, from_path, notest, locallib, mirror, cpanm)
|
||||
|
||||
rc_cpanm, out_cpanm, err_cpanm = module.run_command(cmd, check_rc=False)
|
||||
|
||||
if rc_cpanm != 0:
|
||||
module.fail_json(msg=err_cpanm, cmd=cmd)
|
||||
|
||||
if err_cpanm and 'is up to date' not in err_cpanm:
|
||||
changed = True
|
||||
|
||||
module.exit_json(changed=changed, binary=cpanm, name=name)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
main()
|
||||
@ -1,169 +0,0 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
Ansible module to configure .deb packages.
|
||||
(c) 2014, Brian Coca <briancoca+ansible@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/>.
|
||||
"""
|
||||
|
||||
DOCUMENTATION = '''
|
||||
---
|
||||
module: debconf
|
||||
short_description: Configure a .deb package
|
||||
description:
|
||||
- Configure a .deb package using debconf-set-selections. Or just query
|
||||
existing selections.
|
||||
version_added: "1.6"
|
||||
notes:
|
||||
- This module requires the command line debconf tools.
|
||||
- A number of questions have to be answered (depending on the package).
|
||||
Use 'debconf-show <package>' on any Debian or derivative with the package
|
||||
installed to see questions/settings available.
|
||||
options:
|
||||
name:
|
||||
description:
|
||||
- Name of package to configure.
|
||||
required: true
|
||||
default: null
|
||||
aliases: ['pkg']
|
||||
question:
|
||||
description:
|
||||
- A debconf configuration setting
|
||||
required: false
|
||||
default: null
|
||||
aliases: ['setting', 'selection']
|
||||
vtype:
|
||||
description:
|
||||
- The type of the value supplied
|
||||
required: false
|
||||
default: null
|
||||
choices: [string, boolean, select, multiselect, note, text, password, title]
|
||||
aliases: []
|
||||
value:
|
||||
description:
|
||||
- Value to set the configuration to
|
||||
required: false
|
||||
default: null
|
||||
aliases: ['answer']
|
||||
unseen:
|
||||
description:
|
||||
- Do not set 'seen' flag when pre-seeding
|
||||
required: false
|
||||
default: False
|
||||
aliases: []
|
||||
author: Brian Coca
|
||||
|
||||
'''
|
||||
|
||||
EXAMPLES = '''
|
||||
# Set default locale to fr_FR.UTF-8
|
||||
debconf: name=locales question='locales/default_environment_locale' value=fr_FR.UTF-8
|
||||
|
||||
# set to generate locales:
|
||||
debconf: name=locales question='locales/locales_to_be_generated value='en_US.UTF-8 UTF-8, fr_FR.UTF-8 UTF-8'
|
||||
|
||||
# Accept oracle license
|
||||
debconf: name='oracle-java7-installer' question='shared/accepted-oracle-license-v1-1' value='true' vtype='select'
|
||||
|
||||
# Specifying package you can register/return the list of questions and current values
|
||||
debconf: name='tzdata'
|
||||
'''
|
||||
|
||||
import pipes
|
||||
|
||||
def get_selections(module, pkg):
|
||||
cmd = [module.get_bin_path('debconf-show', True), pkg]
|
||||
rc, out, err = module.run_command(' '.join(cmd))
|
||||
|
||||
if rc != 0:
|
||||
module.fail_json(msg=err)
|
||||
|
||||
selections = {}
|
||||
|
||||
for line in out.splitlines():
|
||||
(key, value) = line.split(':')
|
||||
selections[ key.strip('*').strip() ] = value.strip()
|
||||
|
||||
return selections
|
||||
|
||||
|
||||
def set_selection(module, pkg, question, vtype, value, unseen):
|
||||
|
||||
data = ' '.join([ question, vtype, value ])
|
||||
|
||||
setsel = module.get_bin_path('debconf-set-selections', True)
|
||||
cmd = ["echo '%s %s' |" % (pipes.quote(pkg), pipes.quote(data)), setsel]
|
||||
if unseen:
|
||||
cmd.append('-u')
|
||||
|
||||
return module.run_command(' '.join(cmd), use_unsafe_shell=True)
|
||||
|
||||
def main():
|
||||
|
||||
module = AnsibleModule(
|
||||
argument_spec = dict(
|
||||
name = dict(required=True, aliases=['pkg'], type='str'),
|
||||
question = dict(required=False, aliases=['setting', 'selection'], type='str'),
|
||||
vtype = dict(required=False, type='str', choices=['string', 'boolean', 'select', 'multiselect', 'note', 'text', 'password', 'title']),
|
||||
value= dict(required=False, type='str'),
|
||||
unseen = dict(required=False, type='bool'),
|
||||
),
|
||||
required_together = ( ['question','vtype', 'value'],),
|
||||
supports_check_mode=True,
|
||||
)
|
||||
|
||||
#TODO: enable passing array of optionas and/or debconf file from get-selections dump
|
||||
pkg = module.params["name"]
|
||||
question = module.params["question"]
|
||||
vtype = module.params["vtype"]
|
||||
value = module.params["value"]
|
||||
unseen = module.params["unseen"]
|
||||
|
||||
prev = get_selections(module, pkg)
|
||||
diff = ''
|
||||
|
||||
changed = False
|
||||
msg = ""
|
||||
|
||||
if question is not None:
|
||||
if vtype is None or value is None:
|
||||
module.fail_json(msg="when supliying a question you must supply a valide vtype and value")
|
||||
|
||||
if not question in prev or prev[question] != value:
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
if not module.check_mode:
|
||||
rc, msg, e = set_selection(module, pkg, question, vtype, value, unseen)
|
||||
if rc:
|
||||
module.fail_json(msg=e)
|
||||
|
||||
curr = { question: value }
|
||||
if question in prev:
|
||||
prev = {question: prev[question]}
|
||||
else:
|
||||
prev[question] = ''
|
||||
|
||||
module.exit_json(changed=changed, msg=msg, current=curr, previous=prev)
|
||||
|
||||
module.exit_json(changed=changed, msg=msg, current=prev)
|
||||
|
||||
# import module snippets
|
||||
from ansible.module_utils.basic import *
|
||||
|
||||
main()
|
||||
Loading…
Reference in New Issue