我想配置 Ansible 剧本,添加一些代码来启动服务并向 Telegram 发送通知,但我遇到了如下所示的错误。我认为这不是打字错误,而是社区通用 Telegram 剧本的其他错误。我以前做过这个,没有错误。现在我尝试重新安装新服务器,遵循相同的过程,但出现此错误。
ERROR! couldn't resolve module/action 'community.general.telegram'. This often indicates a misspelling, missing collection, or incorrect module path.
The error appears to be in '/etc/ansible/playbook/start.yml': line 10, column 6, but maybe elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- name: send notify to telegram
^ here
启动.yml
---
- name: testing playbook
hosts: server
tasks:
- name: start apache service
service:
name: apache2
state: started
- name: send notify to telegram
community.general.telegram:
token: 'telegram token'
api_args:
chat_id: telegramid
parse_mode: "markdown"
text: "Apache Web service has been started!"
disable_web_page_preview: True
disable_notification: True
安装过程
echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" | sudo tee -a /etc/apt/sources.list
sudo apt install dirmngr -y
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
sudo apt update
sudo apt install -y ansible
sudo ansible-galaxy collection install community.general
Ansible版本
ansible 2.9.27
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.16 (default, Oct 10 2019, 22:02:15) [GCC 8.3.0]
sudo ansible-galaxy集合安装community.general
Process install dependency map
Starting collection install process
Skipping 'community.general' as it is already installed
答案1
你也在运行ansible-playbook
with吗sudo
? Galaxy 安装和 ansible playbook 运行应使用同一用户。
否则事情看起来是正确的。您可以尝试升级看看是否有帮助:
ansible-galaxy collection install community.general --upgrade