Ansible任务没有安装正确的包

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ansible任务没有安装正确的包相关的知识,希望对你有一定的参考价值。

我在我的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
", "rc": 1, "results": ["Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirror.its.sfu.ca
 * epel: download-ib01.fedoraproject.org
 * extras: mirror.gpmidi.net
 * ius: mirror.slu.cz
 * updates: mirror.it.ubc.ca
Resolving Dependencies
--> Running transaction check
---> Package mod_php70u.x86_64 0:7.0.27-1.ius.centos6 will be installed
--> Processing Dependency: php-common(x86-64) = 7.0.27-1.ius.centos6 for package: mod_php70u-7.0.27-1.ius.centos6.x86_64
--> Running transaction check
---> Package php70u-common.x86_64 0:7.0.27-1.ius.centos6 will be installed
--> Processing Conflict: php71u-common-7.1.14-1.ius.centos6.x86_64 conflicts php-common < 7.1.14-1.ius.centos6
--> Processing Conflict: php71u-common-7.1.14-1.ius.centos6.x86_64 conflicts php70u-common
--> Finished Dependency Resolution
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
"]}

然后,如果我试图看看安装了哪些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
", "rc": 1, "results": ["Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
 * base: mirror.its.sfu.ca
 * epel: mirrors.lug.mtu.edu
 * extras: mirror.gpmidi.net
 * ius: mirror.slu.cz
 * updates: mirror.it.ubc.ca
Resolving Dependencies
--> Running transaction check
---> Package mod_php70u.x86_64 0:7.0.27-1.ius.centos6 will be installed
--> Processing Dependency: php-common(x86-64) = 7.0.27-1.ius.centos6 for package: mod_php70u-7.0.27-1.ius.centos6.x86_64
--> Running transaction check
---> Package php70u-common.x86_64 0:7.0.27-1.ius.centos6 will be installed
--> Processing Conflict: php71u-common-7.1.14-1.ius.centos6.x86_64 conflicts php-common < 7.1.14-1.ius.centos6
--> Processing Conflict: php71u-common-7.1.14-1.ius.centos6.x86_64 conflicts php70u-common
--> Finished Dependency Resolution
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest
"]}

编辑#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}}
答案

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
另一答案

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

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

以上是关于Ansible任务没有安装正确的包的主要内容,如果未能解决你的问题,请参考以下文章

初识ansible

conda 没有使用 ansible playbook 进行初始化

Kubernetes仪表板-尝试生成管理员令牌时出现ansible任务错误

ansible安装

Ansible Tower 发布一个Windows 任务

Ansible的安装配置