|
|
@ -28,20 +28,32 @@ description:
|
|
|
|
|
|
|
|
|
|
|
|
version_added: "0.0.9"
|
|
|
|
version_added: "0.0.9"
|
|
|
|
options:
|
|
|
|
options:
|
|
|
|
pkg:
|
|
|
|
name:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Define the state of a package (install/remove)
|
|
|
|
- name of package to install/remove
|
|
|
|
required: true
|
|
|
|
required: true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
state:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- state of the package installed or absent.
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
update_cache:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- update the package db first (pacman -Syy)
|
|
|
|
|
|
|
|
required: false
|
|
|
|
|
|
|
|
|
|
|
|
author: Afterburn
|
|
|
|
author: Afterburn
|
|
|
|
notes: []
|
|
|
|
notes: []
|
|
|
|
examples:
|
|
|
|
examples:
|
|
|
|
- code: "pacman: name=foo state=latest"
|
|
|
|
- code: "pacman: name=foo state=installed"
|
|
|
|
description: update package db and install package foo
|
|
|
|
description: install package foo"
|
|
|
|
- code: "pacman: name=foo state=absent"
|
|
|
|
- code: "pacman: name=foo state=absent"
|
|
|
|
description: remove package foo
|
|
|
|
description: remove package foo
|
|
|
|
- code: "pacman: name=foo,bar state=absent
|
|
|
|
- code: "pacman: name=foo,bar state=absent
|
|
|
|
description: remove packages foo and bar (if installed)
|
|
|
|
description: remove packages foo and bar
|
|
|
|
|
|
|
|
- code: "pacman: name=bar, state=installed, update_cache=yes"
|
|
|
|
|
|
|
|
description: update the package db (pacman -Syy) then install bar (bar will be the updated if a newer version exists)
|
|
|
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
'''
|
|
|
|
|
|
|
|
|
|
|
@ -55,11 +67,6 @@ PACMAN_PATH = "/usr/bin/pacman"
|
|
|
|
|
|
|
|
|
|
|
|
def query_package(module, name, state="installed"):
|
|
|
|
def query_package(module, name, state="installed"):
|
|
|
|
|
|
|
|
|
|
|
|
# query_package returns True if the package does not
|
|
|
|
|
|
|
|
# need to be installed/upgraded. Otherwise it returns
|
|
|
|
|
|
|
|
# False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pacman -Q returns 0 if the package is installed,
|
|
|
|
# pacman -Q returns 0 if the package is installed,
|
|
|
|
# 1 if it is not installed
|
|
|
|
# 1 if it is not installed
|
|
|
|
if state == "installed":
|
|
|
|
if state == "installed":
|
|
|
@ -71,19 +78,6 @@ def query_package(module, name, state="installed"):
|
|
|
|
return False
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pacman -Qu return 0 if update is needed
|
|
|
|
|
|
|
|
# otherwise it returns 1
|
|
|
|
|
|
|
|
rc = os.system("pacman -Qu %s" % (name))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if rc == 1:
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def update_package_db(module):
|
|
|
|
def update_package_db(module):
|
|
|
|
rc = os.system("pacman -Syy")
|
|
|
|
rc = os.system("pacman -Syy")
|
|
|
|
|
|
|
|
|
|
|
@ -91,7 +85,6 @@ def update_package_db(module):
|
|
|
|
module.fail_json(msg="could not update package db")
|
|
|
|
module.fail_json(msg="could not update package db")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def remove_packages(module, packages):
|
|
|
|
def remove_packages(module, packages):
|
|
|
|
|
|
|
|
|
|
|
|
remove_c = 0
|
|
|
|
remove_c = 0
|
|
|
@ -136,13 +129,13 @@ def install_packages(module, packages):
|
|
|
|
module.exit_json(changed=False, msg="package(s) already installed")
|
|
|
|
module.exit_json(changed=False, msg="package(s) already installed")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
def main():
|
|
|
|
module = AnsibleModule(
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec = dict(
|
|
|
|
argument_spec = dict(
|
|
|
|
state = dict(default="installed", choices=["latest",
|
|
|
|
state = dict(default="installed", choices=["installed","absent"]),
|
|
|
|
"installed",
|
|
|
|
update_cache = dict(default="no", choices=["yes","no"], aliases=["update-cache"]),
|
|
|
|
"absent"]),
|
|
|
|
name = dict(aliases=["pkg"], required=True)))
|
|
|
|
name = dict(default=None, aliases=["pkg"])))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not os.path.exists(PACMAN_PATH):
|
|
|
|
if not os.path.exists(PACMAN_PATH):
|
|
|
@ -151,20 +144,14 @@ def main():
|
|
|
|
p = module.params
|
|
|
|
p = module.params
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if p["name"] == None:
|
|
|
|
if module.boolean(p["update_cache"]):
|
|
|
|
module.fail_json(msg="no packages specified")
|
|
|
|
update_package_db(module)
|
|
|
|
|
|
|
|
|
|
|
|
pkgs = p["name"].split(",")
|
|
|
|
pkgs = p["name"].split(",")
|
|
|
|
|
|
|
|
|
|
|
|
if p["state"] == "installed":
|
|
|
|
if p["state"] == "installed":
|
|
|
|
install_packages(module, pkgs)
|
|
|
|
install_packages(module, pkgs)
|
|
|
|
|
|
|
|
|
|
|
|
# To have the packages at "latest" we need
|
|
|
|
|
|
|
|
# to update the package db first
|
|
|
|
|
|
|
|
elif p["state"] == "latest":
|
|
|
|
|
|
|
|
update_package_db(module)
|
|
|
|
|
|
|
|
install_packages(module, pkgs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif p["state"] == "absent":
|
|
|
|
elif p["state"] == "absent":
|
|
|
|
remove_packages(module, pkgs)
|
|
|
|
remove_packages(module, pkgs)
|
|
|
|
|
|
|
|
|
|
|
|