Ansible任务没有安装正确的包

时间:2018-02-27 17:58:29

标签: ansible ansible-2.x

我在Ansible任务中指定了php70u。但是,ph71u似乎已安装。我想弄明白为什么。

Ansible版本:

me@virtualbox:~/Desktop/ansible_centos$ ansible --version
ansible 2.5.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/me/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.12 (default, Nov 20 2017, 18:23:56) [GCC 5.4.0 20160609]

确认当前没有安装PHP包:

[me@server ~]$ rpm -qa | grep php
[me@server ~]$

确认已安装IUS存储库:

[me@server ~]$ sudo yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.its.sfu.ca
 * epel: mirrors.mit.edu
 * extras: mirror.gpmidi.net
 * ius: ftp.rediris.es
 * updates: mirror.it.ubc.ca
repo id                                                                              repo name
base                                                                                 CentOS-6 - Base
epel                                                                                 Extra Packages for Enterprise Linux 6 - x86_64
extras                                                          
                     CentOS-6 - Extras
ius                                                                                  IUS Community Packages for Enterprise Linux 6 - x86_64
updates                                                                              CentOS-6 - Updates
repolist: 20,549

Ansible任务

- name: install PHP7
  yum: name=php70u state=present

Ansible错误:

TASK [php : install PHP7] ******************************************************
fatal: [local_centos6_vm]: FAILED! => {"changed": false, "msg": "Error: php71u-common conflicts with php70u-common-7.0.27-1.ius.centos6.x86_64\n", "rc": 1, "results": ["Loaded plugins: fastestmirror\nSetting up Install Process\nLoading mirror speeds from cached hostfile\n * base: mirror.its.sfu.ca\n * epel: download-ib01.fedoraproject.org\n * extras: mirror.gpmidi.net\n * ius: mirror.slu.cz\n * updates: mirror.it.ubc.ca\nResolving Dependencies\n--> Running transaction check\n---> Package mod_php70u.x86_64 0:7.0.27-1.ius.centos6 will be installed\n--> Processing Dependency: php-common(x86-64) = 7.0.27-1.ius.centos6 for package: mod_php70u-7.0.27-1.ius.centos6.x86_64\n--> Running transaction check\n---> Package php70u-common.x86_64 0:7.0.27-1.ius.centos6 will be installed\n--> Processing Conflict: php71u-common-7.1.14-1.ius.centos6.x86_64 conflicts php-common < 7.1.14-1.ius.centos6\n--> Processing Conflict: php71u-common-7.1.14-1.ius.centos6.x86_64 conflicts php70u-common\n--> Finished Dependency Resolution\n You could try using --skip-broken to work around the problem\n You could try running: rpm -Va --nofiles --nodigest\n"]}

然后,如果我试着看看安装了哪些PHP软件包,我就明白了:

[me@server ~]$ rpm -qa | grep php
php71u-common-7.1.14-1.ius.centos6.x86_64
php71u-cli-7.1.14-1.ius.centos6.x86_64
php71u-xml-7.1.14-1.ius.centos6.x86_64
php71u-process-7.1.14-1.ius.centos6.x86_64

如果我删除所有php71u*个包裹,我可以手动重新安装:

sudo yum install php70u

[me@server~]$ rpm -qa | grep php
php70u-common-7.0.27-1.ius.centos6.x86_64
mod_php70u-7.0.27-1.ius.centos6.x86_64
[me@server ~]$

编辑#1

使用命令模块而不是yum模块:

- name: install PHP7
  command: yum install php70u

结果:

TASK [php : install PHP7] ******************************************************
 [WARNING]: Consider using yum module rather than running yum

fatal: [local_centos6_vm]: FAILED! => {"changed": true, "cmd": ["yum", "install", "php70u"], "delta": "0:00:02.861760", "end": "2018-02-27 14:22:45.971565", "msg": "non-zero return code", "rc": 1, "start": "2018-02-27 14:22:43.109805", "stderr": "Error: php71u-common conflicts with php70u-common-7.0.27-1.ius.centos6.x86_64", "stderr_lines": ["Error: php71u-common conflicts with php70u-common-7.0.27-1.ius.centos6.x86_64"],

编辑#2

我决定添加删除PHP71u的任务

- name: remove PHP71u
  yum: name=php71u state=absent

- name: install PHP70u
  yum: name=php70u state=present

我遇到了同样的问题:

TASK [php : remove PHP71u] *****************************************************
ok: [local_centos6_vm]

TASK [php : install PHP70u] ****************************************************
fatal: [local_centos6_vm]: FAILED! => {"changed": false, "msg": "Error: php71u-common conflicts with php70u-common-7.0.27-1.ius.centos6.x86_64\n", "rc": 1, "results": ["Loaded plugins: fastestmirror\nSetting up Install Process\nLoading mirror speeds from cached hostfile\n * base: mirror.its.sfu.ca\n * epel: mirrors.lug.mtu.edu\n * extras: mirror.gpmidi.net\n * ius: mirror.slu.cz\n * updates: mirror.it.ubc.ca\nResolving Dependencies\n--> Running transaction check\n---> Package mod_php70u.x86_64 0:7.0.27-1.ius.centos6 will be installed\n--> Processing Dependency: php-common(x86-64) = 7.0.27-1.ius.centos6 for package: mod_php70u-7.0.27-1.ius.centos6.x86_64\n--> Running transaction check\n---> Package php70u-common.x86_64 0:7.0.27-1.ius.centos6 will be installed\n--> Processing Conflict: php71u-common-7.1.14-1.ius.centos6.x86_64 conflicts php-common < 7.1.14-1.ius.centos6\n--> Processing Conflict: php71u-common-7.1.14-1.ius.centos6.x86_64 conflicts php70u-common\n--> Finished Dependency Resolution\n You could try using --skip-broken to work around the problem\n You could try running: rpm -Va --nofiles --nodigest\n"]}

编辑#3

找到脚本后,我使用生成debug_dir的explode参数运行它。然后,我向php求助,找到了一行我找到php70u

[me@server debug_dir]$ grep -ir ".*php.*"
args:{"ANSIBLE_MODULE_ARGS": {"_ansible_version": "2.5.0", "_ansible_selinux_special_fs": ["fuse", "nfs", "vboxsf", "ramfs", "9p"], "name": "php70u", "_ansible_module_name": "yum", "_ansible_verbosity": 3, "_ansible_syslog_facility": "LOG_USER", "_ansible_socket": null, "state": "present", "_ansible_diff": false, "_ansible_debug": false, "_ansible_shell_executable": "/bin/sh", "_ansible_check_mode": false, "_ansible_no_log": false}}

以下是删除PHP71u的内容调试文件:

[me@server debug_dir]$ grep -ir php
args:{"ANSIBLE_MODULE_ARGS": {"_ansible_version": "2.5.0", "_ansible_selinux_special_fs": ["fuse", "nfs", "vboxsf", "ramfs", "9p"], "name": "php71u", "_ansible_module_name": "yum", "_ansible_verbosity": 3, "_ansible_syslog_facility": "LOG_USER", "_ansible_socket": null, "state": "absent", "_ansible_diff": false, "_ansible_debug": false, "_ansible_shell_executable": "/bin/sh", "_ansible_check_mode": false, "_ansible_no_log": false}}

2 个答案:

答案 0 :(得分:0)

RPM抛出的错误消息:

Error: php71u-common conflicts with php70u-common-7.0.27-1.ius.centos6.x86_64

...意味着已经以某种方式安装了php71u

直到找到根本原因,因为您不希望它在安装之前放置任务以删除它:

- name: remove php71u
  yum: name=php71u state=absent

答案 1 :(得分:0)

我的错。我在一个共同的项目列表中自己安装梨,这是另一项任务的一部分。这是在我安装php71u之前安装php70u

我在评论出我的php角色后发现了这一点,手动安装php70u并遇到了我的常用项目列表的问题。