Use Case:-

🔹 Configure Docker

🔹 Start and enable Docker services

🔹 Pull the httpd server image from the Docker Hub

🔹 Run the docker container and expose it to the public

🔹 Copy the html code in /var/www/html directory and start the webserver.

 Ansible PlayBook:-

 - yum_repository:

     name: mydocker

     description: Docker Repo

     file: /etc/yum.repos.d/mydocker


     gpgcheck: no

     enabled: true

  - copy:

     content: "My Docker Web Page"

     dest: "/index.html"

  - command: "yum install docker-ce --nobest -y"

  - package:


      - "yum-utils"

      - "docker-ce, docker-ce-cli,"

      - "python3-pip"

     state: present

  - service:

     name: "firewalld"

     state: stopped

  - ansible.posix.selinux:

     policy: targeted

     state: permissive

  - service:

     name: "docker"

     state: started

  - pip:

     name: "docker"

  - community.general.docker_image:

     name: "httpd"

     source: pull

  - docker_container:

     name: MyWebserverOS

     image: httpd

     state: started

     detach: true

     interactive: true

     ports: "8081:80"

     volumes: /:/usr/local/apache2/htdocs/