Issue
I am using the following ansible script to install php-fpm module in centOS but cannot figure out the error.
---
- hosts: all
become: yes
tasks:
- name: download remi release repo for php
get_url:
url: http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
dest: /tmp/remi-release-6.rpm
tags: php-fpm
- name: install remi repo
shell: /bin/rpm -Uvh /tmp/remi-release-6.rpm
register: remi_repo_result
failed_when: "'conflict' in remi_repo_result.stderr"
tags: php-fpm
- name: enable remi repo
ini_file: dest=/etc/yum.repos.d/remi.repo
section=remi
option=enabled
value=1
- name: install php-fpm and its deps
yum: name={{item}} state=present
with_items:
- php
- php-fpm
tags: php-fpm
- name: backup default php configuration
shell: /bin/cp /etc/php.ini /etc/php.default.ini creates=/etc/php.default.ini
tags: php-fpm
- name: display php errors when not in production
ini_file: dest=/etc/php.ini
section=PHP
option=display_errors
value=On
when: env is defined and env != "production"
notify:
- restart php-fpm
tags: php-fpm
- name: do not show php errors when in production
ini_file: dest=/etc/php.ini
section=PHP
option=display_errors
value=Off
when: env is defined and env == "production"
notify:
- restart php-fpm
tags: php-fpm
- name: backup default php-fpm configuration
shell: /bin/cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.default creates=/etc/php-fpm.d/www.conf.default
tags: php-fpm
- name: change php-fpm to listen on socket
ini_file: dest=/etc/php-fpm.d/www.conf
section=www
option=listen
value=/var/run/php-fpm/php-fpm.sock
notify:
- restart php-fpm
tags: php-fpm
- name: php-fpm listen mode should always be 0666
ini_file: dest=/etc/php-fpm.d/www.conf
section=www
option=listen.mode
value=0666
notify:
- restart php-fpm
tags: php-fpm
- name: change php-fpm user
ini_file: dest=/etc/php-fpm.d/www.conf
section=www
option=user
value=nginx
notify:
- restart php-fpm
tags: php-fpm
- name: change php-fpm group
ini_file: dest=/etc/php-fpm.d/www.conf
section=www
option=group
value=nginx
notify:
- restart php-fpm
tags: php-fpm
- name: start php-fpm
service: name=php-fpm state=running enabled=yes
tags: php-fpm
I get the following error in the task "install php-fpm and its deps"
failed: [127.0.0.1] (item=[u'php', u'php-fpm']) => {"ansible_loop_var": "item", "changed": false, "item": ["php", "php-fpm"], "msg": "Failure talking to yum: Cannot find a valid baseurl for repo: remi"}
Can someone help with a solution for this?
Solution
Note: most of the below is deduced from wild guesses since you did not provide a full and verbose run of the relevant tasks nor the values of the variables for the target you run the playbook against.
There are several issues with your above playbook, the most obvious and relevant one being that
- name: install remi repo
shell: /bin/rpm -Uvh /tmp/remi-release-6.rpm
register: remi_repo_result
failed_when: "'conflict' in remi_repo_result.stderr"
tags: php-fpm
is likelly to not fail although the command is in error.
And since you did not use create: false
on the next ini_file
task, /etc/yum.repos.d/remi.repo
will still be created containing only
[remi]
enabled=1
(For this, I am of course assuming that env
is not set or is different from production
)
From there, the message you get is quite coherent since there is literally no base url for repo remi
.
Some other notes you might want to take into account:
- you can install a remote rpm with the
yum
module by directly passing the url asname
- you should not loop over the
yum
module: pass the list of packages directly in the name attribute (see doc) - don't
cp
with shell, use thecopy
module withremote_src: true
- Use the yaml syntax rather than ini style shortcut syntax
Answered By - Zeitounator Answer Checked By - Terry (WPSolving Volunteer)