-1

任务文件可能有什么问题?

这个角色应该这样做:

  1. 为 vscodium 添加 apt 密钥

  2. 添加 vscodium 存储库

  3. 安装 vscodium

当我想使用 ansible 时$ansible-playbook /etc/ansible/ubuntu_real.yml,会显示此错误:

heavy  ~  ansible-playbook /etc/ansible/ubuntu_real.yml
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

 [WARNING]: Ignoring invalid attribute: repo

 [WARNING]: Ignoring invalid attribute: state


PLAY [localhost] **************************************************************************************************************************************************************************************************

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

TASK [ubuntu_real : Add an Apt signing key for vscodium] **********************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"changed": false, "msg": "Unsupported parameters for (apt_key) module: become, become_method Supported parameters include: data, file, id, key, keyring, keyserver, state, url, validate_certs"}
 [WARNING]: Could not create retry file '/etc/ansible/ubuntu_real.retry'.         [Errno 13] Permission denied: u'/etc/ansible/ubuntu_real.retry'


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

/etc/ansible/roles/ubuntu_real 的任务文件包含错误 apt_key

---
# tasks file for /etc/ansible/roles/ubuntu_real

################################################################
# Resouces
################################################################
# install apt 
# https://docs.ansible.com/ansible/latest/modules/apt_module.html
# add apt_repository
# https://docs.ansible.com/ansible/latest/modules/apt_repository_module.html
################################################################


################################################################
# Vscodium
################################################################
- name: Add an Apt signing key for vscodium
  apt_key:
    url: https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg
    state: present
    become: yes
    become_method: "sudo"

# vscodium add repo
- apt_repository:
  repo: deb https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/repos/debs/ vscodium main
  state: present
  become: yes
  become_method: "sudo"

- name: install vscodium
  apt:
    name: vscodium
    update_cache: yes
    become: yes
    become_method: "sudo"
################################################################

运行角色文件 /etc/ansible/ubuntu_real.yml

---
- hosts: localhost
  connection: local
  roles:
  - ubuntu_real

4

1 回答 1

0

(apt_key) 模块不支持的参数:成为、成为方法

支持的参数包括:data、file、id、key、keyring、keyserver、state、url、validate_certs

是因为become:是任务关键字,而不是模块关键字。您的 yaml 缩进错误;它应该是:

- name: Add an Apt signing key for vscodium
  apt_key:
    url: https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg
    state: present
  become: yes
  become_method: "sudo"
于 2019-06-16T16:37:52.183 回答