You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

本地Ubuntu服务器Ansible部署Apache报错:Failed to update apt cache

在本地Ubuntu服务器通过Ansible Playbook安装Apache2时遇到Apt缓存更新失败问题

尝试在本地Ubuntu服务器上通过Ansible Playbook安装基础apache2,运行Playbook时出现以下错误:

PLAY [Ansible Playbook to Install and Setup Apache on Ubuntu] *******************************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************************************************************************
ok: [localhost]

TASK [Install latest version of Apache] *****************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Failed to update apt cache: unknown reason"}

PLAY RECAP **********************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0 

Playbook中已将hosts变量设置为localhost,尝试了以下两个命令均无法解决问题:

  • ansible-playbook playbook.yml --connection=local
  • ansible-playbook playbook.yml

以下是详细的verbose报错信息:

fatal: [localhost]: FAILED! => {
    "changed": false,
    "invocation": {
        "module_args": {
            "allow_change_held_packages": false,
            "allow_downgrade": false,
            "allow_unauthenticated": false,
            "autoclean": false,
            "autoremove": false,
            "cache_valid_time": 0,
            "clean": false,
            "deb": null,
            "default_release": null,
            "dpkg_options": "force-confdef,force-confold",
            "fail_on_autoremove": false,
            "force": false,
            "force_apt_get": false,
            "install_recommends": null,
            "lock_timeout": 60,
            "name": "apache2",
            "only_upgrade": false,
            "package": [
                "apache2"
            ],
            "policy_rc_d": null,
            "purge": false,
            "state": "latest",
            "update_cache": true,
            "update_cache_retries": 5,
            "update_cache_retry_max_delay": 12,
            "upgrade": null
        }
    },
    "msg": "Failed to update apt cache: unknown reason"
}

内容的提问来源于stack exchange,提问作者deeztesternuts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 02:10:52