0
votes

I'm trying to create a Consul cluster using Ansible and i'm using this example https://github.com/brianshumate/ansible-consul .i'm using the vagrant file to up 3 Ubuntu machines

the problem is that the task Install unzip package seem to always fail,and it gives this error message:

fatal: [consul1.consul -> localhost]: FAILED! => {"changed": false, "msg": "Could not detect which package manager to use. Try gathering facts or setting the \"use\" option."}

Ansible seem unable to recognize the package manager,even though ansible localhost -m setup | grep mgr shows that the variable ansible_pkg_mgr has the value apt

i'm not sure what could be the source of the problem.i tried upping 3 debian machines and i still have the same problem.

UPDATE: here's the task file for consul

---
# File: install.yml - package installation tasks for Consul

- name: Install OS packages
  package:
    name: "{{ item }}"
    state: present
  with_items: "{{ consul_os_packages }}"
  tags: installation

- name: Read package checksum file
  local_action:
    module: stat
    path: "{{ role_path }}/files/consul_{{ consul_version }}_SHA256SUMS"
  become: no
  run_once: true
  register: consul_checksum
  tags: installation

- name: Download package checksum file
  local_action:
    module: get_url
    url: "{{ consul_checksum_file_url }}"
    dest: "{{ role_path }}/files/consul_{{ consul_version }}_SHA256SUMS"
  become: no
  run_once: true
  tags: installation
  when: not consul_checksum.stat.exists | bool

- name: Read package checksum
  local_action:
    module: shell
      grep "{{ consul_pkg }}" "{{ role_path }}/files/consul_{{ consul_version }}_SHA256SUMS" | awk '{print $1}'
  become: no
  run_once: true
  register: consul_sha256
  tags: installation

- name: Check Consul package file
  local_action:
    module: stat
    path: "{{ role_path }}/files/{{ consul_pkg }}"
  become: no
  run_once: true
  register: consul_package
  tags: installation

- name: Download Consul package
  local_action:
    module: get_url
    url: "{{ consul_zip_url }}"
    dest: "{{ role_path }}/files/{{ consul_pkg }}"
    checksum: "sha256:{{ consul_sha256.stdout }}"
    timeout: "42"
  become: no
  run_once: true
  tags: installation
  when: not consul_package.stat.exists | bool

- name: Update alpine package manager (apk)
  local_action:
    module: apk
    update_cache: yes
  run_once: true
  when: lookup('file','/etc/alpine-release')

- name: Install unzip package
  local_action:
    module: package
    name: unzip
    state: present
  run_once: true
  when:
    - consul_install_dependencies | bool

- name: Unarchive Consul package
  local_action:
    module: unarchive
    src: "{{ role_path }}/files/{{ consul_pkg }}"
    dest: "{{ role_path }}/files/"
    creates: "{{ role_path }}/files/consul"
  become: no
  run_once: true
  tags: installation

- name: Install Consul
  copy:
    src: "{{ role_path }}/files/consul"
    dest: "{{ consul_bin_path }}/consul"
    owner: "{{ consul_user }}"
    group: "{{ consul_group }}"
    mode: 0755
  tags: installation

- name: Daemon reload systemd in case the binaries upgraded
  command: systemctl daemon-reload
  become: yes
  notify: restart consul
  when:
    - ansible_service_mgr == "systemd"
    - consul_install_upgrade

- name: Cleanup
  local_action: file path="{{ item }}" state="absent"
  become: no
  with_fileglob: "{{ role_path }}/files/consul"
  run_once: true
  tags: installation
1
You're going to have to post output at higher verbosity and/or a link to the actual task yaml, rather than having us guess which file in that repo is trying to do what you said. Also, be aware that ansible localhost is not the same as running ansible against the vagrant inventory file, as there are many more things that can go wrong when interacting with a system remotely - mdaniel
@MatthewLDaniel it's done in the edit above,and sorry for that,i thought it's obvious to find. actually i tried the same example on a colleague's computer who runs Ubuntu as a main OS (i use Debian),and the execution crashed at the task "Update alpine package manager". maybe you can list the most obvious causes of this kind of errors ? because for me it looks more like an environment issue... - med.b

1 Answers

1
votes

The problem is with the Alpine package Manager,somehow it seem to cause an error with Ubuntu,so all what i did is use Apt instead of Apk.

here's the new version of the task file

---
# File: install.yml - package installation tasks for Consul

- name: Install OS packages
  package:
    name: "{{ item }}"
    state: present
  with_items: "{{ consul_os_packages }}"
  tags: installation

- name: Read package checksum file
  local_action:
    module: stat
    path: "{{ role_path }}/files/consul_{{ consul_version }}_SHA256SUMS"
  become: no
  run_once: true
  register: consul_checksum
  tags: installation

- name: Download package checksum file
  local_action:
    module: get_url
    url: "{{ consul_checksum_file_url }}"
    dest: "{{ role_path }}/files/consul_{{ consul_version }}_SHA256SUMS"
  become: no
  run_once: true
  tags: installation
  when: not consul_checksum.stat.exists | bool

- name: Read package checksum
  local_action:
    module: shell
      grep "{{ consul_pkg }}" "{{ role_path }}/files/consul_{{ consul_version }}_SHA256SUMS" | awk '{print $1}'
  become: no
  run_once: true
  register: consul_sha256
  tags: installation

- name: Check Consul package file
  local_action:
    module: stat
    path: "{{ role_path }}/files/{{ consul_pkg }}"
  become: no
  run_once: true
  register: consul_package
  tags: installation

- name: Download Consul package
  local_action:
    module: get_url
    url: "{{ consul_zip_url }}"
    dest: "{{ role_path }}/files/{{ consul_pkg }}"
    checksum: "sha256:{{ consul_sha256.stdout }}"
    timeout: "42"
  become: no
  run_once: true
  tags: installation
  when: not consul_package.stat.exists | bool

- name: Install unzip package
  apt:
    name: unzip
    state: present
  run_once: true
  when:
    - consul_install_dependencies | bool

- name: Unarchive Consul package
  local_action:
    module: unarchive
    src: "{{ role_path }}/files/{{ consul_pkg }}"
    dest: "{{ role_path }}/files/"
    creates: "{{ role_path }}/files/consul"
  become: no
  run_once: true
  tags: installation

- name: Install Consul
  copy:
    src: "{{ role_path }}/files/consul"
    dest: "{{ consul_bin_path }}/consul"
    owner: "{{ consul_user }}"
    group: "{{ consul_group }}"
    mode: 0755
  tags: installation

- name: Daemon reload systemd in case the binaries upgraded
  command: systemctl daemon-reload
  become: yes
  notify: restart consul
  when:
    - ansible_service_mgr == "systemd"
    - consul_install_upgrade

- name: Cleanup
  local_action: file path="{{ item }}" state="absent"
  become: no
  with_fileglob: "{{ role_path }}/files/consul"
  run_once: true
  tags: installation