Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible 2.3.1.0: Enable repo on CENTOS 7

Tags:

ansible

In order to install php7 seven I need to enable remi-php71 repo using following command:

yum-config-manager --enable remi-php71

How can I do it in an ansible task?

like image 212
hpaknia Avatar asked Jun 17 '17 15:06

hpaknia


3 Answers

I had the same need (but for 5.6). Following the advice in the discussion here I used the following:

- name: enable remi-php56
  ini_file:
    dest: /etc/yum.repos.d/remi.repo
    section: remi-php56
    option: enabled
    value: 1

The advantage over using yum_repository is I don't have to maintain the definition - I install the remi repos from the RPM he provides. The advantage over the shell variant (which should probably be command anyway) is I don't need to run commands and I don't need the yum utils installed just for this

like image 145
Adam Avatar answered Nov 09 '22 22:11

Adam


You can do this to issue that specific shell command:

- name: enable remi-php71
  shell: yum-config-manager --enable remi-php71

Although it is probably better to declare the yum repo itself via something like:

- name: Add remi-php71
  yum_repository:
    name: remi-php71
    description: Remi's PHP 7.1 RPM repository for Enterprise Linux $releasever - $basearch
    mirrorlist: http://rpms.remirepo.net/enterprise/$releasever/php71/mirror
    enabled: yes
    gpgcheck: 1
    gpgkey: http://rpms.remirepo.net/RPM-GPG-KEY-remi

Docs here and here.

like image 14
Alex Harvey Avatar answered Nov 10 '22 00:11

Alex Harvey


You can also enable the repository only during the installation process:

- name: Install PHP packages
  yum:
    name:
      - php
      - php-cli
      - php-common
      - php-devel
      - php-fpm
      - php-gd
      - php-ldap
      - etc...
    state: latest
    enablerepo: "remi,remi-php71"
like image 1
Jack Wire Avatar answered Nov 09 '22 23:11

Jack Wire