{"id":20179132,"url":"https://github.com/pratikshinde55/ansible-apache-change_default_documentroot","last_synced_at":"2025-12-01T12:05:15.335Z","repository":{"id":226223405,"uuid":"768097770","full_name":"Pratikshinde55/Ansible-Apache-Change_default_DocumentRoot","owner":"Pratikshinde55","description":"Using Ansible-playbook for Change in DocumentRoot of Apache Webserver and create custom DocumentRoot in APache webserver and deploy Webpage","archived":false,"fork":false,"pushed_at":"2024-12-26T13:51:20.000Z","size":82,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-13T16:50:33.693Z","etag":null,"topics":["ansible","ansible-playbook","apache-httpd","apache-webserver","aws-ec2","documentroot"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Pratikshinde55.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-06T13:17:14.000Z","updated_at":"2024-12-26T13:56:12.000Z","dependencies_parsed_at":"2025-01-13T16:49:07.759Z","dependency_job_id":"3b064bfa-55da-42bb-a1e6-3575e0406b5a","html_url":"https://github.com/Pratikshinde55/Ansible-Apache-Change_default_DocumentRoot","commit_stats":null,"previous_names":["pratikshinde55/ansible-httpd-documentroot","pratikshinde55/ansible-apache-change_default_documentroot"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pratikshinde55%2FAnsible-Apache-Change_default_DocumentRoot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pratikshinde55%2FAnsible-Apache-Change_default_DocumentRoot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pratikshinde55%2FAnsible-Apache-Change_default_DocumentRoot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Pratikshinde55%2FAnsible-Apache-Change_default_DocumentRoot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Pratikshinde55","download_url":"https://codeload.github.com/Pratikshinde55/Ansible-Apache-Change_default_DocumentRoot/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241616682,"owners_count":19991542,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-playbook","apache-httpd","apache-webserver","aws-ec2","documentroot"],"created_at":"2024-11-14T02:25:18.340Z","updated_at":"2025-12-01T12:05:15.213Z","avatar_url":"https://github.com/Pratikshinde55.png","language":null,"readme":"# Change default DocumentRoot of Apache WEb server by using Ansible Automation:\n![Screenshot 2024-03-08 154000](https://github.com/Pratikshinde55/Ansible-httpd-documentRoot/assets/145910708/ba936d35-a6b9-41fd-89e5-b99b25c5b8f7)\n\n### Apache webserver(httpd):\nIt is a free and open-source Web server Software. It's one of the most widely used web servers in the world, known for its reliability and robustness.\nApache is capable of serving static and dynamic content on the World Wide Web.\n\n- Note: \n\n\" /etc/httpd/ \" or  \"/etc/apache2/ directory\" is common location httpd configuration file.\n\nIn this project, I can create custom Document Root in httpd by using ansible-playbook\n\n## By Ansible Adhoc Command: [Manual way]\n\n1. Install httpd package :\n\n       yum install httpd -y\n\n2. Go inside Httpd internal configuration file , In this file we can create custom documentRoot, \"/etc/httpd/conf.d\" this httpd Default configuration file location:\n\n       cd /etc/httpd/conf.d\n\n3. Create own name or custom name folder inside Httpd configuration file(\"/etc/httpd/conf.d\"), i am creating \"my.conf\" file \u0026 in this file i put my custom documentRoot:\n\n- my.conf file put :--\u003e  DocumentRoot  /var/www/pratik\n\n       vi  my.conf\n\nNow apache web server read from this filder , It means from browser we connect this apache filder \u0026 in this folder we deploy own webpages.\n\n4. After file created then need to restart httpd service (when new settings created ):\n\n       systemctl reload httpd\n\n## By Ansible Automation:  [Ansible-playbook]\n\nI take three AWS Cloud instances Amazon linux EC2, One instance make Ansible-Master \u0026 remaining Instances to make hosts or managed nodes.\n\n![Screenshot 2024-03-07 193702](https://github.com/Pratikshinde55/Ansible-httpd-documentRoot/assets/145910708/eff832e0-d874-4ad5-8013-4a27da87aed4)\n\nIn ansible-master node install ansible-core and connect with target node by ssh key Authentication :\n\n[Ansible-SetUp-onAWS](https://github.com/Pratikshinde55/Ansible-setup-onAWS.git) \n\n## Step-1: [Create file or web page which will weploy ,(index.html) on ansible master node]\n\n![Screenshot 2024-03-07 194123](https://github.com/Pratikshinde55/Ansible-httpd-documentRoot/assets/145910708/53254826-2125-4971-ba8e-f3d1a952c6ca)\n\n## Step-2: [Create playbook ( \"myweb.yml\" my playbook name)]\n\n    vim myweb.yml\n\n![Screenshot 2024-03-07 194019](https://github.com/Pratikshinde55/Ansible-httpd-documentRoot/assets/145910708/232536a4-f6dd-4919-a208-b6dc840f24c0)\n\n- playbook explanation:\n\n A. Here set variables (vars) which for my tasks :-\n\n \"webpage\" variable for my local code or webpage which want to copy and deploy\n \" packageName\" variable for package that i want to install\n \" documentDir\" variable for my own custom documentRoot\n\n\n            - hosts: web\n              vars: \n                webpage: \"index.html\"\n                packageName: \"httpd\"\n                documentDir: \"/var/www/pratik\"\n\n\n B. Install Httpd package here use variable packageName\n\n\n          tasks:\n            - name: \"Install httpd package\"\n              package:\n                name: \"{{ packageName }}\"  \n                state: present\n\n C.  create document root : \n  \n File module is used to create directory \u0026 use state is directory,  This Task createte directory as /var/www/pratik in ansible target nodes :\n\n\n          - name: \"Create Document root for httpd package\"\n            file: \n              state: directory\n              path: \"{{ documentDir }}\"\n\n D. This is very important step Httpd configuration file change: (DocumentRoot)\n \n Here Copy module used to  create \"my.conf\" file at destination \"/etc/httpd/conf.d\" \u0026 and in this \"/etc/httpd/conf.d/my.conf\" file 'content' attribute\n create DocumentRoot = documentDir \"/var/www/pratik\":  \n\n\n\n           - name: \"Create or copy new path in config file\"\n             copy:\n               dest: /etc/httpd/conf.d/my.conf\n               content: |\n                 DocumentRoot {{ documentDir }}\n\n\n E. Deploy local webpage \"index.html to target nodes destination documentDir \"/var/www/pratik/\"\n\n\n          - name: \"Deploy webpage\"\n            copy:\n              src: \"{{ webpage }}\"\n              dest: \"{{ documentDir }}\"\n\n\n F. Reload httpd service, After any change make in httpd configuration file then need to reload or resatrt httpd service then new settings apply:\n\n\n         \n          - name: \"Reload service httpd\"\n            service:\n              name: \"httpd\"\n              state: reloaded\n              enabled: true\n\n\n## Step-4: [Run ansible-playbook] \n\n      ansible-playbook myweb.yml\n\n![Screenshot 2024-03-07 193938](https://github.com/Pratikshinde55/Ansible-httpd-documentRoot/assets/145910708/0469443f-6110-4918-9f5e-ab404410d3a3)\n\n### Here we can see that Automation takes place on Manged node1 \u0026 node2 :\nAt ansible target nodes check what changes happened:\n\n![Screenshot 2024-03-07 194252](https://github.com/Pratikshinde55/Ansible-httpd-documentRoot/assets/145910708/64df6891-ed15-4ac4-a3d2-b59e2c7b2023)\n\n\n![Screenshot 2024-03-07 194309](https://github.com/Pratikshinde55/Ansible-httpd-documentRoot/assets/145910708/bd7ecaeb-cae0-4451-b880-3525d5a60f25)\n\n\n### From google or outside world we can able to connect target Node1 \u0026 node2:\nAnsible Target node 1 : public IP of EC2 instance : node1 : 3.7.69.254\n\n![Screenshot 2024-03-07 194326](https://github.com/Pratikshinde55/Ansible-httpd-documentRoot/assets/145910708/dd65746a-2ca4-4f91-b27c-33fe6eadf01a)\n\nAnsible Target node 2 : public IP of EC2 instance : node2 : 13.201.93.84 \n\n![Screenshot 2024-03-07 194334](https://github.com/Pratikshinde55/Ansible-httpd-documentRoot/assets/145910708/aea89e62-5bf1-4f8e-9bf6-5f413931c0ca)\n\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpratikshinde55%2Fansible-apache-change_default_documentroot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpratikshinde55%2Fansible-apache-change_default_documentroot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpratikshinde55%2Fansible-apache-change_default_documentroot/lists"}