skip to Main Content

I want to configure ansible playbook, put some code for start the service and send notification to the telegram but I got this error. I think this is not typing error but there is something error with the community general telegram. Before this I already run the same process but got no error. Now I try reinstall new server and do the same process and I got this error.

 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

start.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

Installation process

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 Version

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 collection install community.general

Process install dependency map
Starting collection install process
Skipping 'community.general' as it is already installed

2

Answers


  1. According to the documentation you need to add collection keyword

    But also from the documentation for 2.9 version of the module telegram you can do it without collection.

    So, either use:

    collections:
      - community.general
    

    or

       - name: send notify to telegram
         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
    

    It should work.

    Login or Signup to reply.
  2. To use a newer version of community.general with Ansible 2.9, you would need to use, the following syntax, that is the real FQCN of that module:

    community.general.notification.telegram
    

    This problem is happening with many other modules, like:

    community.general.system.puppet
    community.general.files.filesize
    

    For a complete reference, check Github’s project page.

    There’s a discussion about it here too.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search