[ec2-user@ip-172-31-1-74 ~]$ ansible -i inventory amazon -m ping The authenticity of host '172.31.2.198 (172.31.2.198)' can't be established. ED25519 key fingerprint is SHA256:oUNnKraRe4GZHRh28fD1XHDV4AHfqpT0gNps3Xr+27g. This key is not known by any other names The authenticity of host '172.31.2.211 (172.31.2.211)' can't be established. ED25519 key fingerprint is SHA256:UfEdGESzGMp+zUk53FC4lPtOZoGnp1YTw3MF3VewMYw. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? 172.31.2.198 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: Host key verification failed.", "unreachable": true } 172.31.2.211 | UNREACHABLE! => { "changed": false, "msg": "Failed to connect to the host via ssh: Host key verification failed.", "unreachable": true } [ec2-user@ip-172-31-1-74 ~] =========== [ec2-user@ip-172-31-1-74 ~]$ ansible -i inventory amazon -f 1 -m ping The authenticity of host '172.31.2.198 (172.31.2.198)' can't be established. ED25519 key fingerprint is SHA256:oUNnKraRe4GZHRh28fD1XHDV4AHfqpT0gNps3Xr+27g. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes [WARNING]: Platform linux on host 172.31.2.198 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.2.198 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.9" }, "changed": false, "ping": "pong" } The authenticity of host '172.31.2.211 (172.31.2.211)' can't be established. ED25519 key fingerprint is SHA256:UfEdGESzGMp+zUk53FC4lPtOZoGnp1YTw3MF3VewMYw. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes [WARNING]: Platform linux on host 172.31.2.211 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.2.211 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python3.9" }, "changed": false, "ping": "pong" } [ec2-user@ip-172-31-1-74 ~]$ cat inventory [amazon] 172.31.2.198 172.31.2.211 [ec2-user@ip-172-31-1-74 ~]$ ================================================================================ Play Book and dry run --> Installation [ec2-user@ip-172-31-1-74 ~]$ ansible-playbook -i inventory myweb.yml --syntax-check playbook: myweb.yml [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon tasks: - name: "Package Installation" yum: name: httpd,php-fpm state: present [ec2-user@ip-172-31-1-74 ~]$ [ec2-user@ip-172-31-1-74 ~]$ ansible-playbook -i inventory myweb.yml --check PLAY [My Website in Yaml] ********************************************************************************************************************************************** TASK [Gathering Facts] ************************************************************************************************************************************************* [WARNING]: Platform linux on host 172.31.2.198 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. ok: [172.31.2.198] [WARNING]: Platform linux on host 172.31.2.211 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. ok: [172.31.2.211] TASK [Package Installation] ******************************************************************************************************************************************** changed: [172.31.2.211] changed: [172.31.2.198] PLAY RECAP ************************************************************************************************************************************************************* 172.31.2.198 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 172.31.2.211 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 [ec2-user@ip-172-31-1-74 ~]$ ================ [ec2-user@ip-172-31-1-74 ~]$ ansible-playbook -i inventory myweb.yml PLAY [My Website in Yaml] ********************************************************************************************************************************************** TASK [Gathering Facts] ************************************************************************************************************************************************* [WARNING]: Platform linux on host 172.31.2.211 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. ok: [172.31.2.211] [WARNING]: Platform linux on host 172.31.2.198 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. ok: [172.31.2.198] TASK [Package Installation] ******************************************************************************************************************************************** changed: [172.31.2.211] changed: [172.31.2.198] PLAY RECAP ************************************************************************************************************************************************************* 172.31.2.198 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 172.31.2.211 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 [ec2-user@ip-172-31-1-74 ~]$ ================================== [root@ansible-client1 ~]# rpm -qa --last | grep -i httpd httpd-2.4.58-1.amzn2023.x86_64 Mon Mar 18 20:26:21 2024 generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch Mon Mar 18 20:26:21 2024 httpd-tools-2.4.58-1.amzn2023.x86_64 Mon Mar 18 20:26:20 2024 httpd-filesystem-2.4.58-1.amzn2023.noarch Mon Mar 18 20:26:20 2024 httpd-core-2.4.58-1.amzn2023.x86_64 Mon Mar 18 20:26:20 2024 [root@ansible-client1 ~]# date Mon Mar 18 20:26:53 UTC 2024 [root@ansible-client1 ~]# [root@ansible-client2 ~]# rpm -qa --last | grep -i httpd httpd-2.4.58-1.amzn2023.x86_64 Mon Mar 18 20:26:21 2024 generic-logos-httpd-18.0.0-12.amzn2023.0.3.noarch Mon Mar 18 20:26:21 2024 httpd-tools-2.4.58-1.amzn2023.x86_64 Mon Mar 18 20:26:20 2024 httpd-filesystem-2.4.58-1.amzn2023.noarch Mon Mar 18 20:26:20 2024 httpd-core-2.4.58-1.amzn2023.x86_64 Mon Mar 18 20:26:20 2024 [root@ansible-client2 ~]# ============================================================================================= V2 [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon tasks: - name: "Package Installation" yum: name: [ httpd, php-fpm ] state: present [ec2-user@ip-172-31-1-74 ~]$ ======================================== V3 [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: yes hosts: amazon tasks: - name: "Package Installation" yum: name: - "httpd" - "php-fpm" state: installed [ec2-user@ip-172-31-1-74 ~]$ [ec2-user@ip-172-31-1-74 ~]$ ansible-playbook -i inventory myweb.yml PLAY [My Website in Yaml] ********************************************************************************************************************************************** TASK [Gathering Facts] ************************************************************************************************************************************************* [WARNING]: Platform linux on host 172.31.2.198 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. ok: [172.31.2.198] [WARNING]: Platform linux on host 172.31.2.211 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. ok: [172.31.2.211] TASK [Package Installation] ******************************************************************************************************************************************** ok: [172.31.2.211] ok: [172.31.2.198] PLAY RECAP ************************************************************************************************************************************************************* 172.31.2.198 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 172.31.2.211 : ok=2 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 [ec2-user@ip-172-31-1-74 ~]$ ================================================================ Variable Setup ======================== [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon vars: packages: [ httpd, php-fpm ] tasks: - name: "Package Installation" yum: name: "{{ packages }}" state: present [ec2-user@ip-172-31-1-74 ~]$ ==================================================================== Install a new package docker [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon vars: packages: - "httpd" - "php-fpm" - "docker" tasks: - name: "Package Installation" yum: name: "{{ packages }}" state: present [ec2-user@ip-172-31-1-74 ~]$ [root@ansible-client1 ~]# rpm -qa --last | grep -i docker docker-25.0.3-1.amzn2023.0.1.x86_64 Mon Mar 18 20:46:49 2024 [root@ansible-client1 ~]# [root@ansible-client2 ~]# rpm -qa --last | grep -i docker docker-25.0.3-1.amzn2023.0.1.x86_64 Mon Mar 18 20:46:49 2024 [root@ansible-client2 ~]# ================================================================================== Restarting htttpd services [ec2-user@ip-172-31-1-74 ~]$ ansible-playbook -i inventory myweb.yml PLAY [My Website in Yaml] ********************************************************************************************************************************************** TASK [Gathering Facts] ************************************************************************************************************************************************* [WARNING]: Platform linux on host 172.31.2.211 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. ok: [172.31.2.211] [WARNING]: Platform linux on host 172.31.2.198 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. ok: [172.31.2.198] TASK [Package Installation] ******************************************************************************************************************************************** ok: [172.31.2.211] ok: [172.31.2.198] TASK [Restarting the Services] ***************************************************************************************************************************************** changed: [172.31.2.211] changed: [172.31.2.198] PLAY RECAP ************************************************************************************************************************************************************* 172.31.2.198 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 172.31.2.211 : ok=3 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 [ec2-user@ip-172-31-1-74 ~]$ [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon vars: packages: - "httpd" - "php-fpm" - "docker" tasks: - name: "Package Installation" yum: name: "{{ packages }}" state: present - name: "Restarting the Services" service: name: "httpd" state: started enabled: true [ec2-user@ip-172-31-1-74 ~]$ ============================================= Restrting php-fpm & Docker Services =========================== [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon vars: packages: - "httpd" - "php-fpm" - "docker" tasks: - name: "Package Installation" yum: name: "{{ packages }}" state: present - name: "Restarting the Services" service: name: "{{ item }}" state: started enabled: true with_items: - httpd - php-fpm - docker ======================================================== V2 [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon vars: packages: - "httpd" - "php-fpm" - "docker" tasks: - name: "Package Installation" yum: name: "{{ packages }}" state: present - name: "Restarting the Services" service: name: "{{ item }}" state: started enabled: true with_items: [ httpd, php-fpm, docker ] [ec2-user@ip-172-31-1-74 ~]$ ====================================================================== [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon vars: packages: - "httpd" - "php-fpm" - "docker" services: [ httpd, php-fpm, docker ] tasks: - name: "Package Installation" yum: name: "{{ packages }}" state: present - name: "Restarting the Services" service: name: "{{ item }}" state: started enabled: true with_items: "{{ services }}" [ec2-user@ip-172-31-1-74 ~]$ ansible-playbook -i inventory myweb.yml PLAY [My Website in Yaml] ********************************************************************************************************************************************** TASK [Gathering Facts] ************************************************************************************************************************************************* [WARNING]: Platform linux on host 172.31.2.198 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. ok: [172.31.2.198] [WARNING]: Platform linux on host 172.31.2.211 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. ok: [172.31.2.211] TASK [Package Installation] ******************************************************************************************************************************************** ok: [172.31.2.198] ok: [172.31.2.211] TASK [Restarting the Services] ***************************************************************************************************************************************** ok: [172.31.2.198] => (item=httpd) ok: [172.31.2.211] => (item=httpd) ok: [172.31.2.211] => (item=php-fpm) ok: [172.31.2.198] => (item=php-fpm) ok: [172.31.2.211] => (item=docker) ok: [172.31.2.198] => (item=docker) PLAY RECAP ************************************************************************************************************************************************************* 172.31.2.198 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 172.31.2.211 : ok=3 changed=0 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 [ec2-user@ip-172-31-1-74 ~]$ =============================================== [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon vars: packages: - "httpd" - "php-fpm" - "docker" services: - httpd - php-fpm - docker tasks: - name: "Package Installation" yum: name: "{{ packages }}" state: present - name: "Restarting the Services" service: name: "{{ item }}" state: started enabled: true with_items: "{{ services }}" [ec2-user@ip-172-31-1-74 ~]$ ========================================================= External Variables: [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon vars: packages: - "httpd" - "php-fpm" - "docker" services: - httpd - php-fpm - docker webserver_owner: "apache" webserver_group: "apache" tasks: - name: "Package Installation" yum: name: "{{ packages }}" state: present - name: "Restarting the Services" service: name: "{{ item }}" state: started enabled: true with_items: "{{ services }}" tasks: - name: "Copy website Directory" copy: src: ./website/ dest: /var/www/html owner: "{{ webserver_owner }}" group: "{{ webserver_group }}" [ec2-user@ip-172-31-1-74 ~]$ [root@ansible-client1 html]# ll total 56 -rw-r--r--. 1 apache apache 510 Mar 18 21:25 'ABOUT THIS TEMPLATE.txt' drwxr-xr-x. 2 apache apache 117 Mar 18 21:25 css drwxr-xr-x. 2 apache apache 63 Mar 18 21:25 fonts drwxr-xr-x. 4 apache apache 16384 Mar 18 21:25 images -rw-r--r--. 1 apache apache 33124 Mar 18 21:25 index.html drwxr-xr-x. 2 apache apache 184 Mar 18 21:25 js [root@ansible-client1 html]# [root@ansible-client2 html]# ll total 56 -rw-r--r--. 1 apache apache 510 Mar 18 21:25 'ABOUT THIS TEMPLATE.txt' drwxr-xr-x. 2 apache apache 117 Mar 18 21:25 css drwxr-xr-x. 2 apache apache 63 Mar 18 21:25 fonts drwxr-xr-x. 4 apache apache 16384 Mar 18 21:25 images -rw-r--r--. 1 apache apache 33124 Mar 18 21:25 index.html drwxr-xr-x. 2 apache apache 184 Mar 18 21:25 js [root@ansible-client2 html]# ========================================= [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon vars_files: [ variables.yml ] vars: webserver_owner: "apache" webserver_group: "apache" tasks: - name: "Package Installation" yum: name: "{{ packages }}" state: present - name: "Restarting the Services" service: name: "{{ item }}" state: started enabled: true with_items: "{{ services }}" tasks: - name: "Copy website Directory" copy: src: ./website/ dest: /var/www/html owner: "{{ webserver_owner }}" group: "{{ webserver_group }}" [ec2-user@ip-172-31-1-74 ~]$ cat variables.yml --- packages: - "httpd" - "php-fpm" - "docker" services: - httpd - php-fpm - docker [ec2-user@ip-172-31-1-74 ~]$ ==================================================================== [ec2-user@ip-172-31-1-74 ~]$ cat myweb.yml --- - name: "My Website in Yaml" become: true hosts: amazon vars_files: - variables.yml vars: webserver_owner: "apache" webserver_group: "apache" tasks: - name: "Package Installation" yum: name: "{{ packages }}" state: present - name: "Restarting the Services" service: name: "{{ item }}" state: started enabled: true with_items: "{{ services }}" tasks: - name: "Copy website Directory" copy: src: ./website/ dest: /var/www/html owner: "{{ webserver_owner }}" group: "{{ webserver_group }}" ===========================================