Use package module to install bindep packages

We can pass in a list of packages and the package managers we care about
should accept a list as input. We can't do the with_items trick because
the package action plugin does not support it.

Change-Id: Id79f33caa7cb3ab7255490d02cd2b43fc7d5227b
This commit is contained in:
Monty Taylor 2017-07-11 09:39:01 -05:00
parent 2dfb08a49e
commit fe6dc2204d
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 21 additions and 48 deletions

View File

@ -25,53 +25,6 @@
- set_fact:
bindep_run: "{{ bindep_command }} -b -f {{ bindep_file }} {{ bindep_profile }}"
when: bindep_file is defined
# Retry to check that all requested packages are obtained. Sometimes there are
# transient repo issues. This is left as a shell section on purpose rather
# than using ansible package modules because bindep produces a list of packages
# that we feed directly to the package managers.
- name: Install distro packages from bindep
args:
executable: /bin/bash
become: yes
- include: packages.yaml
when: bindep_file is defined
register: result
until: result|succeeded
retries: 3
delay: 5
environment:
DEBIAN_FRONTEND: noninteractive
PATH: /usr/sbin:/sbin:{{ ansible_env.PATH }}
shell: |
# Install test profile using bindep
case {{ ansible_pkg_mgr }} in
apt)
apt-get -qq update
apt-get -q --option "Dpkg::Options::=--force-confold" --assume-yes \
install $({{ bindep_run }})
;;
portage)
emerge -uDNq --jobs=4 @world
emerge -q --jobs=4 $({{ bindep_run }})
;;
zypper)
zypper --non-interactive install $({{ bindep_run }})
;;
dnf|yum)
{{ ansible_pkg_mgr }} install -y $({{ bindep_run }})
;;
*)
echo "Unsupported package manager"
exit 1
;;
esac
if {{ bindep_run }}; then
exit 0
else
exit 1
fi
- fail:
msg: "The packages from the {{ bindep_file }} were not installed"
when: bindep_file is defined and result|failed

View File

@ -0,0 +1,20 @@
- name: Get list of packages to install from bindep
shell: "{{ bindep_run }}"
register: bindep_output
failed_when: false
- name: Install distro packages from bindep
package:
name: "{{ bindep_output.stdout_lines }}"
state: present
become: yes
- name: Check that packages are installed
shell: "{{ bindep_run }}"
register: bindep_final_check
# Ignore errors then fail later so that we can give a better error message
failed_when: false
- fail:
msg: "bindep failed to install from {{ bindep_file}} - {{ bindep_final_check.stdout }}"
when: bindep_final_check|failed