我正在尝试安装一个名为互联网-Pi在我的树莓派上。我已按照说明进行操作,并且我相信一切都已正确安装。我正处于运行 ansible-playbook 的最后一步。
我收到错误:
pi@raspberrypi:~/internet-pi $ ansible-playbook main.yml
ERROR! no action detected in task. This often indicates a misspelled module name, or incorrect module path.
The error appears to have been in '/home/pi/internet-pi/main.yml': line 26, column 7, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
handlers:
- name: Include handlers.
^ here
我不知道从哪里开始解决这个问题。 yml 文件是:
---
- hosts: internet_pi
become: true
pre_tasks:
- name: Load configuration (with defaults from example file).
ansible.builtin.include_vars: "{{ item }}"
loop:
- example.config.yml
- config.yml
- name: Ensure apt cache is up to date.
ansible.builtin.apt:
update_cache: true
cache_valid_time: 3600
when:
- ansible_facts.os_family == "Debian"
- name: Ensure pacman cache is up to date
community.general.pacman:
update_cache: true
when:
- ansible_facts.os_family == "Archlinux"
handlers:
- name: Include handlers.
ansible.builtin.import_tasks: tasks/handlers.yml
tasks:
- name: Setup Docker.
ansible.builtin.import_tasks: tasks/docker.yml
- name: Set up Internet Monitoring.
ansible.builtin.import_tasks: tasks/internet-monitoring.yml
when: monitoring_enable
- name: Set up Pi Hole.
ansible.builtin.import_tasks: tasks/pi-hole.yml
when: pihole_enable
- name: Set up Shelly Plug Monitoring.
ansible.builtin.import_tasks: tasks/shelly-plug.yml
when: shelly_plug_enable
- name: Set up Air Gradient Monitoring.
ansible.builtin.import_tasks: tasks/airgradient.yml
when: airgradient_enable
- name: Set up Starlink Monitoring.
ansible.builtin.import_tasks: tasks/starlink.yml
when: starlink_enable
handlers.yml 是
---
- name: Restart pi-hole
community.docker.docker_compose:
project_src: ~/pi-hole/
build: false
restarted: true
become: false
- name: Restart internet-monitoring
community.docker.docker_compose:
project_src: ~/internet-monitoring/
build: false
restarted: true
become: false
- name: Restart shelly-plug-prometheus
community.docker.docker_compose:
project_src: ~/shelly-plug-prometheus/
build: false
restarted: true
become: false
- name: Restart airgradient-prometheus
community.docker.docker_compose:
project_src: ~/airgradient-prometheus/
build: false
restarted: true
become: false
- name: Restart starlink-exporter
community.docker.docker_compose:
project_src: ~/starlink-exporter/
build: false
restarted: true
become: false
如果我尝试运行,ansible.builtin.import_tasks
我会收到“找不到命令”。
我应该从哪里开始排除故障?
答案1
我在新的 Raspberry Pi 4 上设置 internet-pi 时遇到了同样的问题,所以我决定sudo apt purge ansible
从头sudo apt purge python3-pip
开始。当这样做时,我意识到我在第一次pip3 install ansible
运行后错误地运行了,当时 python3-pip 安装就足够了。sudo apt-get install -y python3-pip
所以我认为随后的 ansible 显式安装在某种程度上搞砸了 ansible 安装。因此,在清除并安装 python3-pip 后,一切正常。
答案2
我认为导入处理程序时您不想有一个 - 名称。用于触发操作的名称将位于 handlers.yml 中。尝试删除 handlers 下的 - name 并将 main.yml 中的 import 语句备份 2 个空格。