无法通过 Ansible 在远程节点上安装软件包

无法通过 Ansible 在远程节点上安装软件包

我已经安装并配置了 Ansible。我的环境如下:

  • 控制机是Ubuntu 14.04
  • 节点是Centos 7

以下是我的hosts文件:

# cat /etc/hosts
127.0.0.1   localhost
192.168.2.100  ubunansible.intern.local ubunansible 
192.168.2.240  node1.intern.local node1
192.168.2.250  node2.intern.local node2

我想将软件包安装到节点,但我不能,尽管 ansible ping 成功从 Ubuntu 到节点:

# ansible -m ping php 
192.168.2.240 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
192.168.2.250 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

我的 php.yml 如下

# cat php.yml
---
- hosts: php
  remote_user: root


  tasks:
  - name: Install required packages
    yum:  update_cache=yes state=latest  name={{ item }}
    with_items:
    - git
    - mcrypt
    - nginx
    - php5-cli
    - php5-curl
    - php5-fpm
    - php5-intl
    - php5-json
    - php5-mcrypt
    - php5-sqlite
    - sqlite3

Yaml语法正确;它是通过在线 yaml 验证器进行检查的。但当我跑步时

$ ansible-playbook php.yml

PLAY [php] ********************************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************
ok: [192.168.2.240]
ok: [192.168.2.250]

TASK [Install required packages] **********************************************************************************************
failed: [192.168.2.250] (item=[u'git', u'mcrypt', u'nginx', u'php5-cli', u'php5-curl', u'php5-fpm', u'php5-intl', u'php5-json', u'php5-mcrypt', u'php5-sqlite', u'sqlite3']) => {"changed": false, "failed": true, "item": ["git", "mcrypt", "nginx", "php5-cli", "php5-curl", "php5-fpm", "php5-intl", "php5-json", "php5-mcrypt", "php5-sqlite", "sqlite3"], "msg": "No package matching 'php5-cli' found available, installed or updated", "rc": 126, "results": ["No package matching 'php5-cli' found available, installed or updated"]}
failed: [192.168.2.240] (item=[u'git', u'mcrypt', u'nginx', u'php5-cli', u'php5-curl', u'php5-fpm', u'php5-intl', u'php5-json', u'php5-mcrypt', u'php5-sqlite', u'sqlite3']) => {"changed": false, "failed": true, "item": ["git", "mcrypt", "nginx", "php5-cli", "php5-curl", "php5-fpm", "php5-intl", "php5-json", "php5-mcrypt", "php5-sqlite", "sqlite3"], "msg": "No package matching 'php5-cli' found available, installed or updated", "rc": 126, "results": ["No package matching 'php5-cli' found available, installed or updated"]}
to retry, use: --limit @/etc/ansible/php.retry

PLAY RECAP ********************************************************************************************************************
192.168.2.240              : ok=1    changed=0    unreachable=0    failed=1   
192.168.2.250              : ok=1    changed=0    unreachable=0    failed=1   

它失败。

答案1

导致 ansible 运行失败的问题在您的最终终端块中给出:

No package matching 'php5-cli' found available, installed or updated

您应该发现,如果您尝试将其安装在节点上,这也会失败没有使用ansible;尝试

node$ sudo apt install php5-cli

php5-cli从您的中删除php.yml并重试。

相关内容