Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify package installation process #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 5 additions & 39 deletions roles/ara_api/tasks/pre-requirements.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,46 +16,12 @@
# You should have received a copy of the GNU General Public License
# along with ARA Records Ansible. If not, see <http://www.gnu.org/licenses/>.

- name: Get list of installed packages
package_facts:
manager: "auto"
no_log: "{{ ara_api_secure_logging }}"

- name: Retrieve list of missing required packages
set_fact:
ara_api_missing_packages: "{{ ara_api_required_packages | difference(ansible_facts['packages'].keys()) }}"

# Only attempt to elevate privileges if there are any missing packages
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather not remove the logic around detecting whether or not packages are already installed and the reason why is in that comment.

In other words, the role is designed to be executable under an unprivileged user if the necessary packages have already been installed: ara can be set up and run within a user's home directory without relying on root or sudo privileges.

By removing this logic, ansible will try to elevate privileges (become: true) and it will not work if Ansible isn't running with root or sudo.

We can remove warn: false if it is an issue, which leaves the fix looking like this instead: Thulium-Drake@91ae432 (thanks @Thulium-Drake).

- when: ara_api_missing_packages | length > 0
- name: Install required packages
package:
name: "{{ ara_api_required_packages }}"
state: present
update_cache: true
become: true
block:
- name: Update apt cache
command: apt-get update
args:
warn: false
when: ansible_facts["os_family"] == "Debian"

- name: Update yum/dnf cache
shell: |
{{ ansible_pkg_mgr }} clean all
{{ ansible_pkg_mgr }} check-update
register: yum_update
failed_when: yum_update['rc'] not in [0, 100]
args:
warn: false
when: ansible_facts["os_family"] == "RedHat"

- name: Install required packages
package:
name: "{{ ara_api_required_packages }}"
state: present
rescue:
- name: Fail due to missing packages
fail:
msg: |
Failed to elevate privileges and install missing required packages.
Install the following packages before running this role again:
{{ ara_missing_packages | join(' ') }}

# The ansible_python_version fact might end up retrieving the version of
# python2 so we need to explicitely get the version of python 3 available.
Expand Down