skip to Main Content

I’m developing my first playbook. I’m using 3 CentOS 8 VMs. Using Oracle Virtual Box on my local pc with Windows 10, which virtualize an Ansible controller VM and 2 target VM’s.

My inventory.txt:

# Inventory File
target1 ansible_ssh_pass=osboxes.org ansible_host=192.168.1.106
target2 ansible_ssh_pass=osboxes.org ansible_host=192.168.1.153

My playbook-webapp.yaml contains:

# Ansible Playbook to install a web application

-
 name: Deploy Web application
 hosts: target1, target2
 remote_user: root
 tasks:
     - name: Install dependencies
       yum: name= {{ item }} state=installed
       with_items:
         - epel-release
         - python
         - python-pi

I execute with:

ansible-playbook playbook-webapp.yaml -i inventory.txt

Output:

PLAY [Deploy Web application] *********************************************************************************************************************

TASK [Gathering Facts] ****************************************************************************************************************************
ok: [target2]
ok: [target1]

TASK [Install dependencies] ***********************************************************************************************************************
ok: [target1] => (item=epel-release)
ok: [target2] => (item=epel-release)
ok: [target1] => (item=python)
ok: [target2] => (item=python)
ok: [target1] => (item=python-pip)
ok: [target2] => (item=python-pip)

PLAY RECAP ****************************************************************************************************************************************
target1                    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0
target2                    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

But when I try to check for my yum repos on target1 node:

[osboxes@target1 ~]$ yum repolist
repo id                         repo name
appstream                       CentOS Linux 8 - AppStream
baseos                          CentOS Linux 8 - BaseOS
extras                          CentOS Linux 8 - Extras

However, no epel-release of some sort is shown, but is set in the ansible task to be installed.

If I try to execute

[osboxes@ansiblecontroller web_deployment]$ ansible all -m ping -i inventory.txt

Output:

target2 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"
}
target1 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    },
    "changed": false,
    "ping": "pong"

Any suggestion is appreciated.

2

Answers


  1. Chosen as BEST ANSWER

    Following the @Kevin suggestions the right playbook is:

    # Ansible Playbook to install a web application
    
    -
     name: Deploy Web application
     hosts: target1, target2
     remote_user: root
     tasks:
         - name: Install dependencies
           dnf:
            name:
             - epel-release
             - python3
             - python3-pip
            state: installed 
    

    To check on the target VMs:

     yum repolist
    

    or

    ls /etc/yum.repos.d/ | grep epel
    

    and

    python3 --version
    

  2. Try to install the package with the dnf module:

    - name: Install dependencies
      dnf:
        name:
          - epel-release
          - python
          - python-pi
    

    Also, a nice approach to manage your systems with Ansible would be to download the operating system, install python3, then package your system again and use that packaged OS for all VM’s. This way, the system is as ‘bald’ as possible, but only includes python3, which is good for Ansible usage.

    no epel-release or other is shown

    This is actually quite weird. This sounds like something you should chase. Since we don’t know the background details here, I can only guess and guide you in the correct direction.

    I am asking myself/you whether you have ‘targetted’ the correct machine. There are 100 ways to verify whether this is the case. I would do it like this:

    - shell: touch /tmp/hi
    

    Then login at the system, and check whether /tmp/hi exists… if it does, then something fishy is going on.

    Check installed packages with:

    rpm -qa | grep -i epel
    

    Is it installed?

    Also, the yum.repos.d should contain the epel repo files

    [vagrant@vm-local-1 ~]$ ls /etc/yum.repos.d/ | grep epel
    epel-modular.repo
    epel-playground.repo
    epel-testing-modular.repo
    epel-testing.repo
    epel.repo
    

    Please let us know.

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