【问题标题】:Upgrade php with Ansible (php7.1 to php7.4)使用 Ansible 升级 php(php7.1 到 php7.4)
【发布时间】:2020-07-01 11:22:11
【问题描述】:

我是一家法国公司的 SysOps,我想编写一个脚本来使用 Ansible 更新 php,但我有一个错误,我没有找到解决方案,我已经安装了 apt-transport-https,在所有机器。 Ansible 安装在 debian9 中,机器也在 debian9 中。

我的脚本


- hosts: all
  sudo: yes
  tasks:
    - apt_repository:
        repo: 'ppa:ondrej/php'
        state: present

    - name: Download the signing key
      shell: wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
      when: ansible_os_family == 'Debian'

    - name: Add the packages in sources lists
      shell: sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
      when: ansible_os_family == 'Debian'

    - name: Update packages
      become: true
      apt:
        update_cache=yes
      when: ansible_os_family == 'Debian'

    - name: Install php
      shell: apt install php7.4 php7.4-common php7.4-cli
      when: ansible_os_family == 'Debian'

    - name: Install extensions
      shell: apt install php7.4-curl php7.4-json php7.4-gd php7.4-mbstring php7.4-intl php7.4-bcmath php7.4-bz2 php7.4-readline php7.4-zip
      when: ansible_os_family == 'Debian'

    - name: Purge php
      shell: apt purge php7.1 libapache2-mod-php7.1
      when: ansible_os_family == 'Debian'

    - name: Check the new version of php
      shell: php -v
      when: ansible_os_family == 'Debian'

和错误:

任务 [更新软件包] ****************************************** ****************************************************** ****************************************************** ****************************************************** ************************ 致命:[192.168.11.138]:失败! => {"changed": false, "msg": "未能更新 apt 缓存:E: 存储库 'http://ppa.launchpad.net/ondrej/php/ubuntustretch Release' 没有发布文件。"} 致命:[192.168.11.137]:失败! => {"changed": false, "msg": "未能更新 apt 缓存:E: 存储库 'http://ppa.launchpad.net/ondrej/php/ubuntustretch Release' 没有发布文件。"} 致命:[192.168.11.142]:失败! => {"changed": false, "msg": "更新 apt 缓存失败:E: 存储库 'http://ppa.launchpad.net/ondrej/php/ubuntustretch Release' 没有发布文件。"} 要重试,请使用:--limit @/etc/ansible/playbooks/upgrade-php.retry

感谢您的帮助:D

【问题讨论】:

  • 在我看来 repo: 'ppa:ondrej/php' 配置不正确。尝试将其设置为不存在的测试,我希望更新将起作用。也可以尝试在机器上手动运行apt update,可能会有更多线索。还有一个小提示,如果你将所有这些任务放在一个块中,那么当 ansible_os_family 时你只需要一个。
  • 好的,我试试,谢谢马丁! :D

标签: php ansible


【解决方案1】:

您已指向 Ubuntu ppa,但没有命名为 stretch 的 Ubuntu 发行版:http://ppa.launchpad.net/ondrej/php/ubuntu/dists/

但是,指定 https://packages.sury.org/php/dists/ apt 存储库的下两行似乎是针对 Debian 特定发行版的,并且确实包含 stretch 版本

所以我相信这是 Martin 所说的和这个建议的混合:如果你的所有机器实际上都是 Debian,则删除 apt_repository: 任务,或者使用 when: 保护该任务,它仅对你的 Ubuntu 评估为 true机器

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-08
    • 2019-02-18
    • 2015-08-04
    • 2016-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多