issue while runing script

230 views
Skip to first unread message

Saillesh Satam

unread,
Jul 24, 2023, 3:11:45 PM7/24/23
to Ansible Project
I am getting below error 

FAILED! => {"changed": false, "msg": "The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead."}

Please help 

---
  - hosts: all
    become: true
    vars:
     ansible_become_pass:
    tasks:
    - name: install ntp
      yum:
       name: ntp
       state: present
      notify:
         run update
    - name: install vim
      yum:
        name: vim
        state: present
    - name: start ntp service
      service:
        name: ntp
        state: started
        enabled: true
    handlers:
      - name: run update
        yum:
           update_cache: yes       

Abhijeet Kasurde

unread,
Jul 24, 2023, 3:26:32 PM7/24/23
to ansible...@googlegroups.com
The Python 2 yum module is needed for this module. If you require Python 3 support use the `dnf` Ansible module instead.

You need to install yum bindings for Python2 or dnf bindings for Python3 on the remote machine.



--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/9108c006-ae4e-4e0b-948b-98fcd1d47436n%40googlegroups.com.


--
Thanks,
Abhijeet Kasurde

Rowe, Walter P. (Fed)

unread,
Jul 24, 2023, 3:30:10 PM7/24/23
to ansible...@googlegroups.com
Use the 'package' module instead of 'yum'. It will do the right thing on each OS. Also, pass all the packages in a single task.

- hosts: all
  become: true
  vars:
    ansible_become_pass:
    pkgs:
      - vim
      - ntp
  tasks:
    - name: "install packages {{ pkgs }}"
      package:
        name: "{{ pkgs }}"
        state: present
      notify: "packages installed"

  handlers:
    - name: start and enable ntp
      service:
        name: ntp
        state: started
        enabled: true
      listen: "packages installed"
    - name: update yum cache
      yum:
        update_cache: yes
      listen: "packages installed"

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

Reply all
Reply to author
Forward
0 new messages