AWX 24.6.1- Default ansible modules not working- Mail, Rsync, visudo,

Default ansible modules not working- Mail, Rsync, visudo,…

**ERROR! couldn't resolve module/action 'mail'. This often indicates a misspelling, missing collection, or incorrect module path.**

17

18

The error appears to be in '/runner/project/playbook.yml': line 37, column 7, but may

19

be elsewhere in the file depending on the exact syntax problem.

20

21

The offending line appears to be:

22

23

24

- name: Send report "{{ outputpath }}" to the mail id "{{ mail_id }}"

25

^ here

26

We could be wrong, but this one looks like it might be an issue with

27

missing quotes. Always quote template expression brackets when they

28

start a value. For instance:

29

30

with_items:

31

- {{ foo }}

32

33

Should be written as:

34

35

with_items:

36

- "{{ foo }}"
- code
 
   - name: Send report "{{ outputpath }}" to the mail id "{{ mail_id }}"
      mail:
        host: mailserver.com
        port: 25
        subject: EXP.O NOW facts.d Report
        body: Hello, Attached is the  server Facts.d Report per your request. Enjoy! 
        from: ansible-cxp.awx@test.com
        to: "{{ mail_id }}"
        attach: "{{ outputpath }}"
      delegate_to: server
      run_once: true

Kindly help me to fix the issue or kindly share the steps to add default modules on AWX EE [24.6.1].
Thanks in advance.

@kurokobo

Hi Vinoth,

That looks like “mail” is part of community.general (please let me know if you’re using a different collection) so I’m seeing a couple of potential issues:

Best regards,

Joe

Thank you @iwt-cmd Joe,
It seems “community.general” has not installed, could you please share the steps to install it.

Regarding mail module, i have also tried “community.general.mail” option but still same error.

 podman run -it quay.io/ansible/awx-ee:24.6.1 ansible-galaxy collection list

# /usr/share/ansible/collections/ansible_collections
Collection              Version
----------------------- -------
amazon.aws              8.0.1
ansible.posix           1.5.4
ansible.windows         2.4.0
awx.awx                 24.6.0
azure.azcollection      2.6.0
community.vmware        4.4.0
google.cloud            1.3.0
kubernetes.core         4.0.0
kubevirt.core           1.4.0
openstack.cloud         2.2.0
ovirt.ovirt             3.2.0
redhatinsights.insights 1.2.2
theforeman.foreman      4.0.0

It depends on how you want to achieve the result.

community.general is not present in quay.io/ansible/awx-ee:24.6.1, so I think you have two possible solutions:

  1. Easy way.

    You can edit the project that will run the playbooks requiring that collection by adding the requirements.yml file in <project dir>/collections:

    for example:

    # tree
    <project dir>
          ├── collections/
          │   └── requirements.yml
    
    # requirements.yml
    ---
    collections:
      - name: community.general
    

    More info at Ansible Galaxy Doc

  2. Advanced way.

    You can create a new Custom Execution Environment using Ansible-builder.

    Introduction to Ansible Builder

    for example:

    # requirements.yml
    ---
    collections:
      - name: community.general
    
    # execution-environment.yml
    version: 1
    build_arg_defaults:
      EE_BASE_IMAGE: "quay.io/ansible/awx-ee:24.6.1"
    dependencies:
      galaxy: requirements.yml
    additional_build_steps:
      prepend:
        - RUN microdnf update -y && microdnf clean all
    
    $ ansible-builder build --ee-file path/to/execution-environment.yml --tag my-custom-ee
    

Thank you @NomakCooper
I have tried first way, created requirements.yml file under gitlab project folder of collection folder and added necessary entry but still community.general has not added in AWX EE.
Screen shot has attached.

And tried to run AWX job again but still getting same mail module missing error.

@kurokobo @NomakCooper
I have also tried to create New custom Execution Environment using Ansible-builder by referring below link. but i am getting below error, could you please check and help on this.

server default python version is 3.9 but i tried to install with 3.11 but still getting error.

[root@server]# /usr/bin/python3.11
Python 3.11.9 (main, Sep 11 2024, 00:00:00) [GCC 11.5.0 20240719 (Red Hat 11.5.0-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
[root@server]# vi execution-environment.yml
[root@server]# ansible-builder build --tag registry.example.com/ansible/ee:2.15-custom --container-runtime docker --verbosity 3
Ansible Builder is generating your execution environment build context.
File context/_build/requirements.yml is already up-to-date.
File context/_build/requirements.txt is already up-to-date.
File context/_build/bindep.txt is already up-to-date.
Creating context/_build/configs
File context/_build/configs/ansible.cfg is already up-to-date.
File context/_build/scripts/assemble is already up-to-date.
File context/_build/scripts/install-from-bindep is already up-to-date.
File context/_build/scripts/introspect.py is already up-to-date.
File context/_build/scripts/check_galaxy is already up-to-date.
File context/_build/scripts/check_ansible is already up-to-date.
File context/_build/scripts/pip_install is already up-to-date.
File context/_build/scripts/entrypoint is already up-to-date.
Ansible Builder is building your execution environment image. Tags: registry.example.com/ansible/ee:2.15-custom
Running command:
  docker build -f context/Dockerfile -t registry.example.com/ansible/ee:2.15-custom context
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
[1/4] STEP 1/17: FROM quay.io/centos/centos:stream9-minimal AS base
[1/4] STEP 2/17: USER root
--> Using cache b39796a2ca659a0ab179d89b4b9175cfd34f40f4b575c80eec98f9015db652d6
--> b39796a2ca65
[1/4] STEP 3/17: ENV PIP_BREAK_SYSTEM_PACKAGES=1
--> Using cache 85985907a9587ee5c71a9b31e60f9258bd60e8db1278a7c853dfe99fe666d289
--> 85985907a958
[1/4] STEP 4/17: ARG EE_BASE_IMAGE
--> Using cache 50958b8a85083f774b46d98d90ad97eb99c4452d523c94634182bef097a530fb
--> 50958b8a8508
[1/4] STEP 5/17: ARG PYCMD
--> Using cache ea99240a2daf00f84de8bd45969fb1fbd38b3e3193bec202138db278f824e226
--> ea99240a2daf
[1/4] STEP 6/17: ARG PYPKG
--> Using cache 7fcbaaff81b1571409223c930a5faa44c0339cbb30f379fb67cc221020fcbe03
--> 7fcbaaff81b1
[1/4] STEP 7/17: ARG PKGMGR_PRESERVE_CACHE
--> Using cache e25056efb4ca106d87d3e8f1786c0d5ae57782ba1a0a49992ac0a319929d624b
--> e25056efb4ca
[1/4] STEP 8/17: ARG ANSIBLE_GALAXY_CLI_COLLECTION_OPTS
--> Using cache 63cb7991ecc968242b7044d58a943c7e132ce76dcab86bab95199661af769753
--> 63cb7991ecc9
[1/4] STEP 9/17: ARG ANSIBLE_GALAXY_CLI_ROLE_OPTS
--> Using cache 0eb11401af6c239ff29d78239944cc2b86ab8ca28f8df3642680a551726d8ddb
--> 0eb11401af6c
[1/4] STEP 10/17: ARG ANSIBLE_INSTALL_REFS
--> Using cache 699458ed97269bec9bc99bce38c67616c0e8c0aa036cf4e1793b204445086ba4
--> 699458ed9726
[1/4] STEP 11/17: ARG PKGMGR
--> Using cache 94ac57b847ca1ee6c5d24ea971927f53f2b911c70a8dc14fe8794ddc23410d61
--> 94ac57b847ca
[1/4] STEP 12/17: COPY _build/scripts/ /output/scripts/
--> Using cache cda4e385974dc0feeb254b21003843f81fba8be28fc7bfc167c1af0f614da69f
--> cda4e385974d
[1/4] STEP 13/17: COPY _build/scripts/entrypoint /opt/builder/bin/entrypoint
--> Using cache 77ccba958ce7c3f349c2d67983b3ec0083d60ca0b56465e69330b60590e2f7ab
--> 77ccba958ce7
[1/4] STEP 14/17: RUN $PKGMGR install $PYPKG -y ; if [ -z $PKGMGR_PRESERVE_CACHE ]; then $PKGMGR clean all; fi
--> Using cache 3c8df7f1e685e365765db1e6398114209de5e479281a3153fc6e0a08e6e7e2e3
--> 3c8df7f1e685
[1/4] STEP 15/17: RUN /output/scripts/pip_install $PYCMD
+ PYCMD=/usr/bin/python3.11
+ '[' -z /usr/bin/python3.11 ']'
+ '[' '!' -x /usr/bin/python3.11 ']'
+ echo '/usr/bin/python3.11 is not an executable'
+ exit 1
/usr/bin/python3.11 is not an executable
Error: building at STEP "RUN /output/scripts/pip_install $PYCMD": while running runtime: exit status 1

An error occurred (rc=1), see output line(s) above for details.
[root@server]#

Unfortunately, I don’t know how else to help you at the moment.

I correctly use the requirements.yml file in my project on my AWX work environment; please check that the AWX project is properly updated with the GitLab project.

Suggestions:

  • Blank lines are allowed, but it’s better to remove them, you never know.
  • Always use the full module syntax, such as community.general.mail.
  • Try checking with a playbook by running a task with delegate_to localhost to verify the list of installed collections.

I followed the guide you provided on my CentOS Stream 9 host with python3.11, and ansible-builder works correctly.

# cat /etc/redhat-release
CentOS Stream release 9
# python3.11 --version
Python 3.11.5
# which python3.11
/usr/local/bin/python3.11

I followed the guide without changing anything except the requirements.yml file.

git clone https://github.com/kurokobo/awx-on-k3s.git
cd awx-on-k3s/builder
# cat dependencies/requirements.yml
---
collections:
  - name: community.general
    version: 10.1.0
    source: https://galaxy.ansible.com
# ansible-builder build --tag registry.example.com/ansible/ee:2.15-custom --container-runtime docker --verbosity 3
...
...
...
Successfully tagged registry.example.com/ansible/ee:2.15-custom
a3ea2d8254df02afa2e9cf66f23b8a20ea9a3387743ebcfe213d73a428332a4f

Complete! The build context can be found at: /root/awx-on-k3s/builder/context
# docker image ls registry.example.com/ansible/ee:2.15-custom
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
REPOSITORY                       TAG          IMAGE ID      CREATED        SIZE
registry.example.com/ansible/ee  2.15-custom  a3ea2d8254df  2 minutes ago  297 MB
# podman run -it registry.example.com/ansible/ee:2.15-custom ansible-galaxy collection list

# /usr/share/ansible/collections/ansible_collections
Collection        Version
----------------- -------
community.general 10.1.0
3 Likes

+1 for @NomakCooper

After your collections/requirements.yml is added to your project, you have to sync your project in AWX, since the installation of the specified collections is one of the steps of updating your project.

Then refer to the logs of the job to update your project to see if the collections are installed for your project.

1 Like

Thank you @NomakCooper for checking on local setup.
For Easy way -
For Advanced way - I will try to do fresh OS installation and try again on another server.

Thank you very much @kurokobo
While sync my project in AWX, i got below error, i will check and update here.

It appears that your environment cannot reach the Ansible Galaxy servers, and for this reason, the installation and sync of the project are not being performed.

If you are unable to reach the Galaxy servers for the installation process, you can try using the tarball archive:

  • Manually download the version you are interested in from Ansible Galaxy.

  • Upload the tarball into the collections directory.

  • Change the requirements.yml file to this:

    collections:
      - name: community-general-10.4.0.tar.gz
        type: file
    

Perhaps this could work.

1 Like

Thank you very much @NomakCooper
Manually i have downloaded the tar file and placed under collections directory and updated the requirements.yml file.
Now i successfully able to sync the project and mail module is working fine.:slight_smile: :slight_smile:

Finally it is working fine.

1 Like