From b030d787fdfcc5877f2962b7669e3ca7a68e06f6 Mon Sep 17 00:00:00 2001 From: Sebastien Bocahu Date: Mon, 13 Aug 2012 19:06:53 +0200 Subject: [PATCH 1/3] Fixed scoping issue in apt_repository module. --- apt_repository | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/apt_repository b/apt_repository index 675439d0043..3fe7dceb8da 100755 --- a/apt_repository +++ b/apt_repository @@ -26,10 +26,9 @@ import platform APT = "/usr/bin/apt-get" -ADD_APT_REPOSITORY = None -def _find_binary(): +def _find_binary(module): binaries = ['/usr/bin/add-apt-repository'] for e in binaries: @@ -48,6 +47,8 @@ def _run(cmd): def main(): + add_apt_repository = None + arg_spec = dict( repo=dict(required=True), state=dict(default='present', choices=['present', 'absent']) @@ -55,12 +56,12 @@ def main(): module = AnsibleModule(argument_spec=arg_spec) - ADD_APT_REPOSITORY = _find_binary() + add_apt_repository = _find_binary(module) repo = module.params['repo'] state = module.params['state'] - rc, out, err = _run('%s %s --remove' % (ADD_APT_REPOSITORY, repo)) + rc, out, err = _run('%s %s --remove' % (add_apt_repository, repo)) existed = 'Error' not in out if state == 'absent': @@ -69,7 +70,7 @@ def main(): else: module.exit_json(changed=True, repo=repo, state=state) - cmd = '%s %s' % (ADD_APT_REPOSITORY, repo) + cmd = '%s %s' % (add_apt_repository, repo) if float(platform.dist()[1]) >= 11.10: cmd = cmd + ' -y' From 41422e852c62cd8bab9e0d10b3a1ed4fe876ea01 Mon Sep 17 00:00:00 2001 From: Sebastien Bocahu Date: Mon, 13 Aug 2012 19:23:53 +0200 Subject: [PATCH 2/3] Add support for Debian in apt_repository --- apt_repository | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apt_repository b/apt_repository index 3fe7dceb8da..b495b7fed18 100755 --- a/apt_repository +++ b/apt_repository @@ -72,7 +72,7 @@ def main(): cmd = '%s %s' % (add_apt_repository, repo) - if float(platform.dist()[1]) >= 11.10: + if platform.dist()[0] == 'debian' or float(platform.dist()[1]) >= 11.10: cmd = cmd + ' -y' rc, out, err = _run(cmd) From c7ada98af048109d4b647cbd072d5d7ee033fa2a Mon Sep 17 00:00:00 2001 From: Sebastien Bocahu Date: Mon, 13 Aug 2012 19:36:08 +0200 Subject: [PATCH 3/3] Quote the repository string when appending it to the command line in the apt_repository module. --- apt_repository | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apt_repository b/apt_repository index b495b7fed18..8724f7c301e 100755 --- a/apt_repository +++ b/apt_repository @@ -61,7 +61,7 @@ def main(): repo = module.params['repo'] state = module.params['state'] - rc, out, err = _run('%s %s --remove' % (add_apt_repository, repo)) + rc, out, err = _run('%s "%s" --remove' % (add_apt_repository, repo)) existed = 'Error' not in out if state == 'absent': @@ -70,7 +70,7 @@ def main(): else: module.exit_json(changed=True, repo=repo, state=state) - cmd = '%s %s' % (add_apt_repository, repo) + cmd = '%s "%s"' % (add_apt_repository, repo) if platform.dist()[0] == 'debian' or float(platform.dist()[1]) >= 11.10: cmd = cmd + ' -y'