A
A
Anton2019-07-20 19:04:47
Vagrant
Anton, 2019-07-20 19:04:47

Why in one case, installing a pip package via ansible in Vagrant requires sudo rights, but not in the other?

There is a Vagrantfile

ip = "192.168.33.198";
Vagrant.configure("2") do |config|
  config.vm.network "forwarded_port", guest: 80, host: 80
  config.vm.network "forwarded_port", guest: 443, host: 443
  config.vm.box = "centos/7"
  config.vm.hostname = "zabbix"
  config.vm.define "zabbix"
  config.vm.network "private_network", ip: ip
  config.vm.provider "virtualbox" do |vb|
    vb.memory = "3096"
  end
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbook.yml"
  end
end

playbook.yml
- hosts: all
  become: yes
  roles:
     - { role: dj-wasabi.zabbix-agent }

Here is the block of code where the error is:
- name: "Install local python-netaddr package"
  pip:
    name: netaddr
    state: present
  register: zabbix_python_netaddr_package_installed
  until: zabbix_python_netaddr_package_installed is succeeded
  delegate_to: localhost
  become: "{{ zabbix_agent_become_on_localhost }}" - это True
  when:
    - zabbix_install_pip_packages | bool
    - ansible_all_ipv4_addresses is defined or (zabbix_agent_ip is not defined and total_private_ip_addresses is defined)

Gives an error message:
TASK [dj-wasabi.zabbix-agent : Install local python-netaddr package] ***********
FAILED - RETRYING: Install local python-netaddr package (3 retries left).
FAILED - RETRYING: Install local python-netaddr package (2 retries left).
FAILED - RETRYING: Install local python-netaddr package (1 retries left).
fatal: [zabbix -> localhost]: FAILED! => {"attempts": 3, "changed": false, "module_stderr": "sudo: требуется пароль\n", "module_stdout": "", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

There is a second playbook.yml
- hosts: all
  become: yes
  gather_facts: yes
  tasks:
    - name: test which user I am
      shell: whoami
      register: hello
    - debug: msg="{{ hello.stdout }}"
    - name: Install EPEL repo.
      yum:
        name: epel-release
        state: present
    - name: Install python-pip
      yum:
        name: python-pip
        state: present
    - name: "Install local python-netaddr package"
      pip:
        name: netaddr
        state: present
      register: netaddr_installed
      become: True
    - debug: msg="{{ netaddr_installed.stdout }}"

Doesn't throw an error.
TASK [Install local python-netaddr package] ************************************
changed: [zabbix]

TASK [debug] *******************************************************************
ok: [zabbix] => {
    "msg": "Collecting netaddr\n  Downloading https://files.pythonhosted.org/packages/ba/97/ce14451a9fd7bdb5a397abf99b24a1a6bb7a1a440b019bebd2e9a0dbec74/netaddr-0.7.19-py2.py3-none-any.whl (1.6MB)\nInstalling collected packages: netaddr\nSuccessfully installed netaddr-0.7.19\n"
}

Why in one case, installing a pip package via ansible in Vagrant requires sudo rights, but not in the other?
Thanks

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Georg Gaal, 2019-07-20
@gecube

1. There are two become in the first playbook. Is this done on purpose?
2. Show your ansible.cfg
3. Well, in general, in general, there should be password-free sudo everywhere or the correct ansible.cfg settings (that's why item 2 was born).
4. Other things being equal, it's always better to install python packages through axis's native package manager than through pip. Yes, there are situations when this is impossible or undesirable, but in principle you can make the same packages yourself if they are not in the official OS distribution

A
Anton, 2019-07-20
Patsev

become: "{{ zabbix_agent_become_on_localhost }}" - in the variable True
become: True removed
ansible.cfg - no. tried in it. tried pipeline - but didn't help.
In general, here
https://github.com/dj-wasabi/ansible-zabbix-agent/...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question