我对 Ansible 非常陌生,我正在尝试在 EC2 实例(Ubuntu 18.04)上安装 kubectl 来上课。
我已经运行了剧本,一切进展顺利,直到遇到任务 4,然后抛出以下错误:
致命:[localhost]:失败! => {“changed”:false,“msg”:“无法更新 apt 缓存:W:无法安全地从此类存储库进行更新,因此默认禁用。, W:请参阅 apt-secure(8 ) 存储库创建和用户配置详细信息的联机帮助页。, W:GPG 错误:https://packages.cloud.google.com/aptkubernetes-xenial InRelease:由于公钥不可用,无法验证以下签名:NO_PUBKEY FEEA9169307EA071 NO_PUBKEY 8B57C5C2836F4BEB,E:存储库“https://apt.kubernetes.io kubernetes-xenial InRelease”未签名。 }
现在,每当我尝试再次运行任务 1 时,它都会引发相同的错误。有人可以建议我如何解决这个问题吗?
这是我写的剧本,它基于我完成的使用 Ansible 安装 Docker 的练习以及为我安装 kubectl 提供的命令:
- name: A playbook to install kubectl on a VM
hosts: localhost
user: ubuntu
become: yes
tasks:
- name: 1. Update APT Package Manager
apt:
update_cache: yes
- name: 2. Install dependency packages
apt:
name={{ item }}
with_items:
- apt-transport-https
- ca-certificates
- curl
- gnupg-agent
- software-properties-common
- name: 3. Get APT Key
shell:
cmd: curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cmd: echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
- name: 4. Update Packages
apt:
update_cache: yes
- name: 5. Install Kubectl
apt:
update_cache: yes
name: kubectl
关于部分
- name: 3. Get APT Key
shell:
cmd: curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
cmd: echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee -a /etc/apt/sources.list.d/kubernetes.list
The shell_module只会执行第二个cmd
。 Ansible 只能将其中一个参数传递给模块,即最后一个。
To 从 HTTPS 下载文件到节点你可以使用get_url_module,后面跟着一个apt_key_module 任务添加 apt 密钥.
- name: Download apt key
get_url:
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
dest: /tmp # or /etc/pki/rpm-gpg depending on the infrastructure
- name: Add a key from a file
ansible.builtin.apt_key:
file: /tmp/apt-key.gpg
state: present
您也可以通过以下方式添加
- name: Add an Apt signing key, uses whichever key is at the URL
ansible.builtin.apt_key:
url: https://packages.cloud.google.com/apt/doc/apt-key.gpg
state: present
或者如果您已经知道密钥 ID
- name: Add missing Apt signing key by ID from a keyserver
ansible.builtin.apt_key:
keyserver: keyserver.ubuntu.com
id: "{{ KEY_ID }}"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)