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

     baseurl: https://download.docker.com/linux/centos/7/x86_64/stable

     gpgcheck: no

     enabled: true

  - copy:

     content: "My Docker Web Page"

     dest: "/index.html"

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

  - package:

     name:

      - "yum-utils"

      - "docker-ce, docker-ce-cli, containerd.io"

      - "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/