我正在学习如何使用 ansible,并为我的本地桌面编写剧本。我正在使用 atom 编辑器并安装了 linter。我在编写时没有收到任何错误,但是当我执行剧本时,我收到错误“有问题的行似乎是”
Here's my current Playbook:
---
- hosts: localhost
tasks:
- name: Install .deb packages from the internet.
apt:
deb:
- https://packagecloud.io/AtomEditor/atom/any/
- https://updates.signal.org/desktop/apt
- http://ppa.launchpad.net/webupd8team/brackets/ubuntu
- http://ppa.launchpad.net/nextcloud-devs/client/ubuntu
- http://repository.spotify.com stable non-free
- http://download.xnview.com/XnConvert-linux-x64.deb
- https://updates.signal.org/desktop/apt xenial main
- name: Install a list of packages
update_cache: yes
apt:
pkg:
- AtomEditor
- brackets
- calibre
- chromium-browser
- filezilla
- firefox-locale-de
- gimp
- gparted
- gscan2pdf
- gstreamer1.0-pulseaudio
- keepassxc
- nextcloud-client
- nextcloud-client-nautilus
- pdfshuffler
- python-nautilus
- spotify
- tipp10
- vlc
- XnConvert
- name: no tracking
become: true
vars:
packages_absent:
- apport
- gnome-intial-setup
- ubuntu-web-launchers
- name: Remove useless packages from the cache
apt:
autoclean: yes
- name: Remove dependencies that are no longer required
apt:
autoremove: yes
然后我的终端告诉我:
The offending line appears to be:
tasks:
- name: no tracking
^ here
我知道这是初学者的问题,我的剧本中可能还有很多问题。但我很乐意得到任何帮助。
答案1
注意参数的缩进:
看起来该deb:
参数(及其其余部分)需要更大的缩进。因此,而不是,
- name: Install .deb packages from the internet.
apt:
deb:
- https://packagecloud.io/AtomEditor/atom/any/
- ...
添加一些缩进deb:
使其成为参数,
- name: Install .deb packages from the internet.
apt:
deb:
- https://packagecloud.io/AtomEditor/atom/any/
- ...
如果没有缩进,Ansible 将无法理解deb:
为apt:
模块的参数;相反,它将尝试将其理解为影响如何apt:
使用的指令(例如notify:
,等)become:
ignore_errors:
同样update_cache:
如此,而不是,
- name: Install a list of packages
update_cache: yes
apt:
pkg:
- AtomEditor
- ...
移至update_cache:
内部apt:
并缩进,
- name: Install a list of packages
apt:
update_cache: yes
pkg:
- AtomEditor
- ...
相似地,
- name: Remove useless packages from the cache
apt:
autoclean: yes
最后我不明白你想用“无追踪”部分;我不知道模块vars:
。也许你想删除这些包(如果存在),在这种情况下,请参阅模块的文档apt:
,尤其是‘删除“foo”包’ 例子。