diff --git a/ispmail.yml b/ispmail.yml index 222293d..85398ef 100644 --- a/ispmail.yml +++ b/ispmail.yml @@ -4,6 +4,7 @@ roles: - ispmail-packages - dumpvars + - thydel.patch - ispmail-certificate - ispmail-database - ispmail-postfix diff --git a/roles/ispmail-postfix/tasks/main.yml b/roles/ispmail-postfix/tasks/main.yml index bdda855..8f61864 100644 --- a/roles/ispmail-postfix/tasks/main.yml +++ b/roles/ispmail-postfix/tasks/main.yml @@ -67,6 +67,12 @@ - name: Enabling SMTP authentication during the SMTP protocol command: postconf smtpd_recipient_restrictions=permit_mynetworks,permit_sasl_authenticated,reject_unauth_destination +- name: Copying patch for Debuan bug \#739738 + copy: src=spamassassin.patch dest=/tmp/spamassassin.patch + +- name: Patching Debian bug \#739738 + patch: patchfile=/tmp/spamassassin.patch strip=0 basedir=/ + - name: Enabling Spamassassin milter command: postconf smtpd_milters=unix:/spamass/spamass.sock diff --git a/roles/thydel.patch/.gitignore b/roles/thydel.patch/.gitignore new file mode 100644 index 0000000..5367209 --- /dev/null +++ b/roles/thydel.patch/.gitignore @@ -0,0 +1,8 @@ +.hg/ +.hgignore +.hgremote +.gitconfig +.gitremote +.gitfirstcommit +.hgfirstcommit +README.html diff --git a/roles/thydel.patch/LICENSE.md b/roles/thydel.patch/LICENSE.md new file mode 100644 index 0000000..c8b6af8 --- /dev/null +++ b/roles/thydel.patch/LICENSE.md @@ -0,0 +1,9 @@ +The MIT License (MIT) + +Copyright (c) 2014 Thierry Delamare + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/roles/thydel.patch/README.md b/roles/thydel.patch/README.md new file mode 100644 index 0000000..d9d59f4 --- /dev/null +++ b/roles/thydel.patch/README.md @@ -0,0 +1,40 @@ +# Patch + +Ansible role to embed patch module + +- Original `patch` module from + [luisperlaz/ansible-misc-modules](https://github.com/luisperlaz/ansible-misc-modules) + +- Reorganize filetree to fit `galaxy` and new repos to get a better galaxy name. + +- Patch module to support +[check-mode](https://github.com/thydel/ansible-misc-modules/commit/ecee1b0d830917bc2f88998f1e47deaca293f799) + +## Example Playbook + +After declaring `patch` role: + +``` yaml +- hosts: all + roles: + - patch +``` + +You can use patch module: + +``` yaml +- name: Patch some paramiko code + patch: patchfile=/tmp/critical.patch strip=1 basedir=/usr/share/pyshared/paramiko" +``` + +## Prerequisites: + +GNU patch installed + +## License + +MIT + +## Author Information + +Thierry Delamare diff --git a/roles/thydel.patch/library/patch b/roles/thydel.patch/library/patch new file mode 100755 index 0000000..29a07fb --- /dev/null +++ b/roles/thydel.patch/library/patch @@ -0,0 +1,117 @@ +#!/usr/bin/python -tt + +# (c) 2012, Luis Alberto Perez Lazaro +# +# This module 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. +# +# This software 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 this software. If not, see . +# + +DOCUMENTATION = ''' +--- +module: patch +author: Luis Alberto Perez Lazaro +version_added: 0.9 +short_description: apply patch files +description: + - Apply patch files using the GNU patch tool. Before using this module make sure the patch tool is installed. +options: + patchfile: + required: true + description: + - A patch file as accepted by the gnu patch tool + strip: + required: true + aliases: [ p ] + description: + - Number that indicates the smallest prefix containing leading slashes that + will be stripped from each file name found in the patch file. For more information + see the strip parameter of the gnu patch tool. + basedir: + required: true + description: + - base directory in which the patch file will be applied +examples: + - code: "patch: patchfile=/tmp/critical.patch strip=1 basedir=/usr/share/pyshared/paramiko" + description: Example git checkout from Ansible Playbooks +''' + +def _run(args): + cmd = subprocess.Popen(args, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + out, err = cmd.communicate() + rc = cmd.returncode + return (rc, out, err) + +def _is_already_applied(patch_file, strip): + reverse_cmd = "patch -s -R -N -p%s --dry-run < %s" % (strip, patch_file) + (rc, _, _) = _run(reverse_cmd) + return rc == 0 + +def _apply_patch(module, patch_file, strip): + patch_cmd = "patch -s -N -t -r - -p%s < %s" % (strip, patch_file) + (rc, out, err) = _run(patch_cmd) + if rc != 0: + msg = out if not err else err + module.fail_json(msg=msg) + +def _get_params(module): + patchfile = os.path.expanduser(module.params['patchfile']) + strip = module.params['strip'] + basedir = module.params['basedir'] + + if basedir: + os.chdir(os.path.expanduser(basedir)) + + if not os.path.exists(patchfile): + module.fail_json(msg="patchfile %s doesn't exist" % (patchfile)) + if not os.access(patchfile, os.R_OK): + module.fail_json(msg="patchfile %s not readable" % (patchfile)) + + if not os.path.exists(basedir): + module.fail_json(msg="basedir %s doesn't exist" % (patchfile)) + + try: + strip = int(strip) + except Exception: + module.fail_json(msg="p must be a number") + + return patchfile, strip, basedir + +# =========================================== + +def main(): + module = AnsibleModule( + argument_spec = dict( + patchfile=dict(required=True), + basedir=dict(), + strip=dict(default=0, aliases=['p']) + ), + supports_check_mode = True + ) + patchfile, strip, basedir = _get_params(module) + + changed = False + + if module.check_mode: + if _is_already_applied(patchfile, strip): + module.exit_json(changed=changed) + module.exit_json(changed=True) + + if not _is_already_applied(patchfile, strip): + _apply_patch(module, patchfile, strip) + changed = True + + module.exit_json(changed=changed) + +# include magic from lib/ansible/module_common.py +#<> +main() diff --git a/roles/thydel.patch/meta/.galaxy_install_info b/roles/thydel.patch/meta/.galaxy_install_info new file mode 100644 index 0000000..9c83965 --- /dev/null +++ b/roles/thydel.patch/meta/.galaxy_install_info @@ -0,0 +1 @@ +{install_date: 'Mon Oct 5 13:52:12 2015', version: master} diff --git a/roles/thydel.patch/meta/main.yml b/roles/thydel.patch/meta/main.yml new file mode 100644 index 0000000..edd39e2 --- /dev/null +++ b/roles/thydel.patch/meta/main.yml @@ -0,0 +1,10 @@ +--- +galaxy_info: + author: Thierry Delamare + description: Embed patch module + company: EpiConcept + license: MIT + min_ansible_version: 1.3 + categories: + - packaging +dependencies: [] diff --git a/roles/thydel.patch/tasks/main.yml b/roles/thydel.patch/tasks/main.yml new file mode 100644 index 0000000..ed97d53 --- /dev/null +++ b/roles/thydel.patch/tasks/main.yml @@ -0,0 +1 @@ +---