[ec2-user@ansible-master ~]$ pwd /home/ec2-user [ec2-user@ansible-master ~]$ cat inventory [amazon] 172.31.11.153 ansible_user="ec2-user" [ec2-user@ansible-master ~]$ ================================= ping test [ec2-user@ansible-master ~]$ ansible -i inventory amazon -m ping [WARNING]: Platform linux on host 172.31.11.153 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information. 172.31.11.153 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.9" }, "changed": false, "ping": "pong" } [ec2-user@ansible-master ~]$ ===================================== User creation [ec2-user@ansible-master ~]$ ansible -i inventory amazon -b -m user -a "name=ranjith" [WARNING]: Platform linux on host 172.31.11.153 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information. 172.31.11.153 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.9" }, "changed": true, "comment": "", "create_home": true, "group": 1001, "home": "/home/ranjith", "name": "ranjith", "shell": "/bin/bash", "state": "present", "system": false, "uid": 1001 } [ec2-user@ansible-master ~]$ =============================================== [ec2-user@ansible-master ~]$ ansible -i inventory amazon -b -m shell -a "id ranjith" [WARNING]: Platform linux on host 172.31.11.153 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information. 172.31.11.153 | CHANGED | rc=0 >> uid=1001(ranjith) gid=1001(ranjith) groups=1001(ranjith) [ec2-user@ansible-master ~]$ ================================================ Deleted user account [ec2-user@ansible-master ~]$ ansible -i inventory amazon -b -m user -a "name=ranjith state=absent" [WARNING]: Platform linux on host 172.31.11.153 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information. 172.31.11.153 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.9" }, "changed": true, "force": false, "name": "ranjith", "remove": false, "state": "absent" } [ec2-user@ansible-master ~]$ ansible -i inventory amazon -b -m shell -a "id ranjith" [WARNING]: Platform linux on host 172.31.11.153 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information. 172.31.11.153 | FAILED | rc=1 >> id: ‘ranjith’: no such usernon-zero return code [ec2-user@ansible-master ~]$ =============================================================== Httpd installation [ec2-user@ansible-master ~]$ ansible -i inventory amazon -m yum -a "name=httpd state=present" [WARNING]: Platform linux on host 172.31.11.153 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information. 172.31.11.153 | FAILED! => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.9" }, "changed": false, "msg": "This command has to be run under the root user.", "results": [] } [ec2-user@ansible-master ~]$ ansible -i inventory amazon -b -m yum -a "name=httpd state=present" [WARNING]: Platform linux on host 172.31.11.153 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information. 172.31.11.153 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.9" }, "changed": true, "msg": "", "rc": 0, "results": [ "Installed: httpd-filesystem-2.4.58-1.amzn2023.noarch", "Installed: httpd-2.4.58-1.amzn2023.x86_64", "Installed: mod_lua-2.4.58-1.amzn2023.x86_64", "Installed: apr-util-1.6.3-1.amzn2023.0.1.x86_64", "Installed: generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch", "Installed: httpd-tools-2.4.58-1.amzn2023.x86_64", "Installed: apr-1.7.2-2.amzn2023.0.2.x86_64", "Installed: mod_http2-2.0.11-2.amzn2023.x86_64", "Installed: httpd-core-2.4.58-1.amzn2023.x86_64", "Installed: libbrotli-1.0.9-4.amzn2023.0.2.x86_64", "Installed: mailcap-2.1.49-3.amzn2023.0.3.noarch", "Installed: apr-util-openssl-1.6.3-1.amzn2023.0.1.x86_64" ] } [ec2-user@ansible-master ~]$ ======================================================================= php-fpm installation [ec2-user@ansible-master ~]$ ansible -i inventory amazon -b -m yum -a "name=php-fpm state=present" [WARNING]: Platform linux on host 172.31.11.153 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information. 172.31.11.153 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.9" }, "changed": true, "msg": "", "rc": 0, "results": [ "Installed: php8.2-common-8.2.15-1.amzn2023.0.1.x86_64", "Installed: php8.2-fpm-8.2.15-1.amzn2023.0.1.x86_64", "Installed: nginx-filesystem-1:1.24.0-1.amzn2023.0.2.noarch" ] } [ec2-user@ansible-master ~]$ ==================================================================== Services restart [ec2-user@ansible-master ~]$ ansible -i inventory amazon -b -m service -a "name=httpd state=started" [WARNING]: Platform linux on host 172.31.11.153 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information. 172.31.11.153 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.9" }, "changed": true, "name": "httpd", "state": "started", "status": { [ec2-user@ansible-master ~]$ ansible -i inventory amazon -b -m service -a "name=httpd enabled=true" [WARNING]: Platform linux on host 172.31.11.153 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information. 172.31.11.153 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.9" }, "changed": true, "enabled": true, "name": "httpd", =========== [ec2-user@ansible-master ~]$ ansible -i inventory amazon -b -m service -a "name=php-fpm enabled=true" [WARNING]: Platform linux on host 172.31.11.153 is using the discovered Python interpreter at /usr/bin/python3.9, but future installation of another Python interpreter could change the meaning of that path. See https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html for more information. 172.31.11.153 | CHANGED => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.9" }, "changed": true, "enabled": true, "name": "php-fpm", ==================================================== Copy the directory to remote hosts [ec2-user@ansible-master ~]$ ansible -i inventory amazon -b -m copy -a "src=website/ dest=/var/www/html/ owner=apache group=apache" 172.31.11.153 | CHANGED => { "changed": true, "dest": "/var/www/html/", "src": "/home/ec2-user/website/" } [ec2-user@ansible-master ~]$ ============================================ Validations from client machine ============================================= [ec2-user@ip-172-31-11-153 html]$ ll total 56 -rw-r--r--. 1 apache apache 510 Mar 15 15:18 'ABOUT THIS TEMPLATE.txt' drwxr-xr-x. 2 apache apache 117 Mar 15 15:18 css drwxr-xr-x. 2 apache apache 63 Mar 15 15:18 fonts drwxr-xr-x. 4 apache apache 16384 Mar 15 15:18 images -rw-r--r--. 1 apache apache 33124 Mar 15 15:18 index.html drwxr-xr-x. 2 apache apache 184 Mar 15 15:18 js [ec2-user@ip-172-31-11-153 html]$ [ec2-user@ip-172-31-11-153 html]$ [ec2-user@ip-172-31-11-153 html]$ curl http://ec2-13-232-225-252.ap-south-1.compute.amazonaws.com/