Ansible Install Package Error

Hii,

I’m trying to install packages with ansible on the app servers. This is task number 2, level 2. I successfully installed the package and activated their service. I’m also able to verify this by SSH-ing into that particular server. However, I’m still encountering an error while validating the task. Please help me with this issue. @Alistair_KodeKloud I’m facing the same issue with other packages like httpd, zip, and vim-enhanced.


inventory

[app_servers]
stapp01 ansible_host=172.16.238.10 ansible_user=tony
stapp02 ansible_host=172.16.238.11 ansible_user=steve
stapp03 ansible_host=172.16.238.12 ansible_user=banner

playbook.yml

---
- name: Install and Configure Samba
  hosts: app_servers
  become: yes
  tasks:
    - name: Install Samba
      package:
        name: samba
        state: present
      when: ansible_facts['os_family'] == "Debian" or ansible_facts['os_family'] == "RedHat"

    - name: Configure smb.conf
      template:
        src: smb.conf.j2
        dest: /etc/samba/smb.conf
      notify: restart samba

  handlers:
    - name: restart samba
      service:
        name: smb
        state: restarted

smb.conf.j2

[global]
   workgroup = WORKGROUP
   server string = Samba Server
   log file = /var/log/samba/log.%m
   max log size = 50
   security = user
   passdb backend = tdbsam

[shared]
   path = /srv/samba/shared 
   writable = yes 
   guest ok = yes 
   read only = no

I think the task asks you to use yum to install the packages. You don’t need a when clause and also it doesn’t say to configure or restart samba, just install it.



That looks correct. Was your inventory called inventory?

Hi @34_Aniket-Kale ,

Thanks for highlighting this. I forwarded your concern to the KKE team. They’ll look into this.

Regards,

@34_Aniket-Kale You haven’t defined the SSH credentials in the inventory file you shared, did you setup the passwod-less SSH from jump host to the apps servers before running the playbook?

Can you please share each step you took along with your inventory and playbook so that we can replicate this issue on our end.

yeah i have setup password-less ssh and this is my inventory file

[app_servers]
stapp01 ansible_host=172.16.238.10 ansible_user=tony
stapp02 ansible_host=172.16.238.11 ansible_user=steve
stapp03 ansible_host=172.16.238.12 ansible_user=banner

step 1: setup password less ssh
ssh-keygen
step 2:
ssh-copy-id tony@stapp01
ssh-copy-id steve@stapp02
ssh-copy-id banner@stapp03

step 3: verify password less auth conf successfully done by doing sshing into each server without password

step 4: cd playbook
step 5: created inventory file as mentioned above
step 6: created playbook.yml file as mentioned above
step 7: executed ansible playbook
ansible-playbook -i inventory playbook.yml

mentioning both files again
inventory

[app_servers]
stapp01 ansible_host=172.16.238.10 ansible_user=tony
stapp02 ansible_host=172.16.238.11 ansible_user=steve
stapp03 ansible_host=172.16.238.12 ansible_user=banner

playbook.yml

---
- name: Install wget
  hosts: app_servers
  become: yes
  tasks:
    - name: Install wget
      yum:
        name: wget
        state: present

@34_Aniket-Kale It should be good now, fixed a bug in the validation script. Please try this again and thanks for reporting this issue.


@inderpreetaps thanks for your quick support but still im getting same issue.

Strange, I tried a few times, but it seems to be passing. Could you try once more, probably the changes were not reflected on prod when you retried it.

Perhaps, but in the end, it has worked now, and the task is successful. So, am I getting any reward points for reporting this bug and investing my time into it? LOL. :sweat_smile:

1 Like