1

I'm trying to install elasticsearch from a "common" role but ansible can't find the package to install.

i'm getting the following error when i'm executing playbook:

failed: [vm1] (item=elasticsearch) => {
    "ansible_facts": {
        "pkg_mgr": "dnf"
    },
    "ansible_loop_var": "item",
    "changed": false,
    "failures": [
        "No package elasticsearch available."
    ],
    "item": "elasticsearch",
    "rc": 1,
    "results": []
}

MSG:

Failed to install some of the specified packages

Here's the code from the main.yml from tasks.

- name: install java
  yum:
    state: latest
    update_cache: yes
  with_items:
    - default-jdk


- name: install elasticsearch rpm key
  rpm_key:
    key: https://artifacts.elastic.co/GPG-KEY-elasticsearch
    state: present
  become: true

- name: install elasticsearch 8.x rpm repository
  yum_repository:
    name: Elasticsearch repository for 8.x packages
    description: Elasticsearch repository for 8.x packages
    baseurl: https://artifacts.elastic.co/packages/8.x/yum
    gpgkey: https://artifacts.elastic.co/GPG-KEY-elasticsearch
    enabled: 0
  become: true

- name: install elasticsearch 8.x
  yum:
    name: "{{ item }}"
    state: present
    update_cache: true
  with_items:
    - elasticsearch
  become: true

- name: reload systemd config
  systemd: daemon_reload=yes

- name: enable service elasticsearch and ensure it is not masked
  systemd:
    name: elasticsearch
    enabled: yes
    masked: no

In the vm i can that the in /etc/yum.repos.d/ the repo is being inserted normally.

4
  • what if you login to the vm, and simply execute 'sudo dnf install elasticsearch' Commented Apr 26, 2023 at 10:15
  • @KevinC do you mean manually? Commented Apr 26, 2023 at 10:17
  • exactly, 'manually' Commented Apr 26, 2023 at 10:18
  • My goal is to do it through Ansible, manually it works fine Commented Apr 26, 2023 at 10:19

1 Answer 1

0

If you can install elasticsearch 'manually', then it should also work via Ansible.

Installing via yum should not be done via a loop. Try it like so:

- name: install elasticsearch 8.x
  dnf:
    name: elasticsearch
    state: present
  become: true

Do note, you can remove the 'unmasking' of the service, as this is unrequired.
Also reloading deamons is unrequired.

Sign up to request clarification or add additional context in comments.

2 Comments

still the same error :(
if installing manually via the vm works with 'sudo dnf install elasticsearch', but not via ansible, are you then targeting the correct vm? the package name is named 'elasticsearch'. if all fails, you can try to use the official ansible role for elasticsearch: github.com/elastic/ansible-elasticsearch

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.