-1

I am trying to install Php, Apache in RHEL using the Ansible Playbook. But I am getting following error.

*failed: [18.191.65.251] (item=[u'php', u'php-mysql', u'php-pdo', u'php-gd', u'php-mbstring']) => {"ansible_loop_var": "item", "changed": false, "failures": ["No package php-mysql available."], "item": ["php", "php-mysql", "php-pdo", "php-gd", "php-mbstring"], "msg": ["Failed to install some of the specified packages"], "rc": 1, "results": []}

Screenshot of error

The code that I have used to write the playbook is as follows

---
- hosts: all

  become: yes

  tasks:

 - name: Install httpd

    yum:

    name: httpd

    state: present

 - name: starting httpd service

    service:

    name: httpd

    enabled: yes

    state: started

- name: Installing php packages

   yum:

   name: "{{ item }}"

   state: present

 with_items:
 - php
 - php-mysql
 - php-pdo
 - php-gd
 - php-mbstring

- name: restart Apache service

   service:
   name: httpd
   state: restarted
Armaan
  • 127
  • 2
  • 2
  • 7
  • 3
    Possible duplicate of [yum install php-mysql unable to install Centos](https://stackoverflow.com/questions/25872600/yum-install-php-mysql-unable-to-install-centos) – Mostafa Hussein Jun 30 '19 at 07:05
  • 1
    Are you able to install it from the command line? – Vladimir Botka Jun 30 '19 at 11:52
  • Side note: don't use `with_items` with yum but pass the list directly to the `name` parameter. See the [first note on the module doc](https://docs.ansible.com/ansible/latest/modules/yum_module.html#notes) – Zeitounator Jun 30 '19 at 21:25

1 Answers1

0

Use Amazon Linux instead of RHEL, rest code will code work.


  • hosts: all

    become: yes

    tasks:

    • name: Install httpd

    yum:

    name: httpd

    state: present

    • name: starting httpd service

    service:

    name: httpd

    enabled: yes

    state: started

  • name: Installing php packages

    yum:

    name: "{{ item }}"

    state: present

    with_items:

    • php
    • php-mysql
    • php-pdo
    • php-gd
    • php-mbstring
  • name: restart Apache service

    service: name: httpd state: restarted

Armaan
  • 127
  • 2
  • 2
  • 7