I am new to ansible and writing a playbook to install locustio with python3 on a Ubuntu 18.04. I don't know how to install locustio with pip3 in playbook. If use pip package, then it gives error to use older version of locust. ( use a pinned old locust version (pip/pip3 install locustio==0.13.5) . I would like to know how to install locust with pip3 or locust 0.13.5 version with pip?
- hosts: all
tasks:
- name: Create folder to keep the files
file:
path: /opt/locust
state: directory
mode: '0755'
become: yes
- name: Python installation
apt:
name: ['python3']
state: present
become: yes
- name: Pip installation
apt:
name: ['python3-pip']
state: present
become: yes
- name: pip install
apt:
name: ['python-pip']
state: present
become: yes
- name: Locust Installation
pip:
name: ['locustio']
state: present
become: yes
I haven't used Ansible, but looking at the docs there seems to be a executable parameter that you could set to pip3.
Related
Ansible version: 2.9
Python version being used: 3.6+
OS: ubuntu 18
Trying to remove docker-py using pip.
Code snippets I have tried...
post_tasks:
- pip:
name: docker-py
state: absent
- name: remove docker-py sdk
pip:
name: docker-py
state: absent
Document referred: https://docs.ansible.com/ansible/2.9/modules/docker_container_module.html
package never gets uninstalled.
Direct pip command from shell works
pip uninstall docker-py
- name: remove docker-py sdk
become: no
pip:
name: docker-py
state: absent
I had become: yes for the whole ansible-playbook, i did a override for this task, so may be we should avoid become: yes for pip packages.
I have:
ignore_errors: false
become: yes
become_method: sudo
yum:
name: ["epel-release", "clamav"]
state: present
update_cache: yes
It complains that no package found, but I need to install epel-release before I can install clamav because it lives in epel repo. Is there a way to ensure the order? What are the options besides splitting to 2 stanzas? Thanks.
Ansible loop can solve like below.
ignore_errors: false
become: yes
become_method: sudo
yum:
name: "{{ item }}"
state: present
update_cache: yes
loop:
- "epel-release"
- "clamav"
Although using a loop as proposed by #Haldum should effectively solve your issue, its use is discouraged in yum module documentation. Since you definitely need to add the epel repo prior to using it, I would create two tasks where you can eventually install several packages in the second.
- name: install my things
hosts: my_hostgroup
become: true
vars:
my_packages:
- clamav
# - some other package maybe
tasks:
- name: Install prerequisite epel repo
yum:
name: epel-release
state: present
- name: Install required packages
yum:
name: "{{ my_packages }}"
state: present
Currently, I am trying to use the ansible.builtin.expect.
Here is my usecase:
- name: Set password for built-in user
expect: command: '/usr/share/elasticsearch/bin/elasticsearch-keystore add "bootstrap.password" -f'
responses: Enter value for bootstrap.password: 'test'
To use ansible.builtin.expect I have to install:
python >= 2.6
pexpect >= 3.3
I have Python 2.7.5 installed, but if i want to install pexpect, it only installs version 2.3.
To install pexpect i use:
- name: Install pexpect module
yum:
name: pexpect
state: latest
Does anyone know, how I am able to install pexpect version 3.3?
Why not installing directly the pip version matching your requirement:
- name: Install pexpect throuhg pip
become: true
pip:
name: "pexpect>=3.3"
state: present
something like this maybe:
- name: 'install pexpect'
become: true
become_user: 'root'
yum:
name: '{{ item }}'
state: present
enablerepo: 'standard'
with_items:
- 'pexpect'
I need to use with_items loop to install apache2, sqlite3, and git in Ansible. I'm trying to use the below code but it seems like nothing is happening.
---
- hosts: all
sudo: yes
name: install apache2, sqlite3, git on remote server
tasks:
- name: Install list of packages
action: apt pkg={{item}} state=installed
with_items:
- apache2
- sqlite3
- git
you have to place the variable item inside the double quotes...
Try this code it'll work:
---
- name: install apache2, sqlite3, git on remote servers
hosts: all
become: true
tasks:
- name: Install packages
package:
name: "{{item}}"
state: present
loop:
- apache2
- sqlite3
- git
Try
---
- name: install apache2, sqlite3, git on remote servers
hosts: all
sudo: true
tasks:
- name: Install packages
package:
name: {{ item }}
state: present
loop:
- apache2
- sqlite3
- git
See package – Generic OS package manager
"This module actually calls the pertinent package modules for each system (apt, yum, etc)."
See apt – Manages apt-packages if you need apt specific attributes.
I was using ansible to install pexpect on both my vagrant box and also onto my host. When I installed pexpect onto both computers, the version is 4.6.0, but when using ansible to install using apt-get, the maximum version is only 3.1. The error message thrown is: "Insufficient version of pexpect installed (3.1), this module requires pexpect>=3.3. Error was __init__() got an unexpected keyword argument 'echo'"}How am I able to install pexpect in order to use the expect module for ansible?
The code for downloading pexpect is
- hosts: all
become: yes
become_user: root
gather_facts: no
#can use sudo/sudo_user instead of become, but thats depreceated in ansible 2.6 or later
tasks:
- name: download pip
apt: name=python3-pip state=latest
- name: update pexpect
command: pip3 install pexpect
command: pip3 install --upgrade pip3
command: pip3 install --upgrade pexpect
Run a task per command and try to use Ansible pip module.
- name: Install Pexpect
hosts: all
become: True
become_user: root
gather_facts: False
tasks:
- name: download pip
apt:
name: python3-pip
state: latest
- name: Install Pexpect
pip:
name: pexpect
state: latest
- name: Upgrade pip - Force reinstall to the latest version
pip:
name: pip
state: forcereinstall