Ansibleで Failed to update apt cache
というメッセージが表示されてエラーとなる原因を調査したのでメモします。
環境
- ansible : 2.9.11
発生した事象
- Ansibleで
Failed to update apt cache
というメッセージが表示されてエラーとなる
原因
- Ansibleでデプロイ対象のサーバ(EC2)が外部と通信できない
AWS上に作成したEC2のSecurity GroupのOutbound通信が許可されていないこちらの事象が原因でした。
$ ansible-playbook -i ./hosts main.yml
PLAY [ubuntu] ************************************************************************************************************************************************
TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [vpn-check-c-plane-mme-ec2]
TASK [common : Install packages] *****************************************************************************************************************************
[DEPRECATION WARNING]: Invoking "apt" only once while using a loop via squash_actions is deprecated. Instead of using a loop to supply multiple items and
specifying `name: "{{item}}"`, please use `name: ['curl', 'git', 'python-pip', 'software-properties-common', 'zip']` and remove the loop. This feature will
be removed in version 2.11. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.
failed: [vpn-check-c-plane-mme-ec2] (item=['curl', 'git', 'python-pip', 'software-properties-common', 'zip']) => {"ansible_loop_var": "item", "changed": false, "item": ["curl", "git", "python-pip", "software-properties-common", "zip"], "msg": "Failed to update apt cache: "}
NO MORE HOSTS LEFT *******************************************************************************************************************************************
PLAY RECAP ***************************************************************************************************************************************************
example-ec2 : ok=1 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0
EC2のOutbound通信を許可したら、問題なく実行できました。