Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -------------------------------------------------------------- Task 1-------------------------------------------
- ec2-user@ip-172-31-5-142 ~]$ cat inventory
- [amazon]
- 172.31.5.5 ansible_port=22 ansible_ssh_user="ec2-user" ansible_ssh_private_key_file="aws.pem"
- 172.31.7.82 ansible_port=22 ansible_ssh_user="ec2-user" ansible_ssh_private_key_file="aws.pem"
- [ec2-user@ip-172-31-5-142 ~]$ ansible -i inventory amazon -f 1 -m ping
- The authenticity of host '172.31.5.5 (172.31.5.5)' can't be established.
- ED25519 key fingerprint is SHA256:X6J9GdLG8a2dDY3/KBJpqaXtm0Bxy9aRYF4mNABwvnc.
- This key is not known by any other names
- Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
- 172.31.5.5 | SUCCESS => {
- "ansible_facts": {
- "discovered_interpreter_python": "/usr/bin/python3.9"
- },
- "changed": false,
- "ping": "pong"
- }
- The authenticity of host '172.31.7.82 (172.31.7.82)' can't be established.
- ED25519 key fingerprint is SHA256:lsR/+H4FcaYos/3+msnbGnznOo7/23ZYNnrV2Umx2lA.
- This key is not known by any other names
- Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
- 172.31.7.82 | SUCCESS => {
- "ansible_facts": {
- "discovered_interpreter_python": "/usr/bin/python3.9"
- },
- "changed": false,
- "ping": "pong"
- }
- [ec2-user@ip-172-31-5-142 ~]$ git clone https://github.com/Chris-luiz-16/aws-elb-site.git website/
- Cloning into 'website'...
- remote: Enumerating objects: 248, done.
- remote: Counting objects: 100% (13/13), done.
- remote: Compressing objects: 100% (13/13), done.
- remote: Total 248 (delta 2), reused 5 (delta 0), pack-reused 235
- Receiving objects: 100% (248/248), 1.45 MiB | 9.19 MiB/s, done.
- [ec2-user@ip-172-31-5-142 ~]$ cat lampstack-install.yml
- ---
- - name: "LAMP installation for php website"
- hosts: amazon
- become: true
- vars:
- httpd_owner: apache
- httpd_group: apache
- packages:
- - httpd
- - php
- - mariadb105-server
- tasks:
- - name: "LAMP packages installation"
- yum:
- name: "{{ packages }}"
- state: present
- - name: "httpd service enable"
- service:
- name: httpd
- state: started
- enabled: true
- - name: "php service enable"
- service:
- name: php-fpm
- state: started
- enabled: true
- - name: "mariadb service enable"
- service:
- name: mariadb
- state: started
- enabled: true
- - name: "Copying website to the document root"
- copy:
- src: ./website/
- dest: /var/www/html/
- owner: "{{ httpd_owner }}"
- group: "{{ httpd_group }}"
- [ec2-user@ip-172-31-5-142 ~]$ ansible-playbook -i inventory lampstack-install.yml
- PLAY [LAMP installation for php website] *******************************************************************************
- TASK [Gathering Facts] *************************************************************************************************
- [WARNING]: Platform linux on host 172.31.7.82 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.7.82]
- [WARNING]: Platform linux on host 172.31.5.5 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.5.5]
- TASK [LAMP packages installation] **************************************************************************************
- changed: [172.31.7.82]
- changed: [172.31.5.5]
- TASK [httpd service enable] ********************************************************************************************
- changed: [172.31.7.82]
- changed: [172.31.5.5]
- TASK [php service enable] **********************************************************************************************
- changed: [172.31.7.82]
- changed: [172.31.5.5]
- TASK [mariadb service enable] ******************************************************************************************
- changed: [172.31.5.5]
- changed: [172.31.7.82]
- TASK [Copying website to the document root] ****************************************************************************
- changed: [172.31.5.5]
- changed: [172.31.7.82]
- PLAY RECAP *************************************************************************************************************
- 172.31.5.5 : ok=6 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- 172.31.7.82 : ok=6 changed=5 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- -------------------------------------------------------------- Task 2 [variables declaration] -------------------------------------------
- [ec2-user@ip-172-31-5-142 ~]$ cat packages.yml && echo
- ---
- packages:
- - httpd
- - php
- - mariadb105-server
- [ec2-user@ip-172-31-5-142 ~]$
- [ec2-user@ip-172-31-5-142 ~]$
- [ec2-user@ip-172-31-5-142 ~]$ cat apache-group.yml && echo
- ---
- httpd_owner: apache
- httpd_group: apache
- [ec2-user@ip-172-31-5-142 ~]$
- [ec2-user@ip-172-31-5-142 ~]$
- [ec2-user@ip-172-31-5-142 ~]$ cat lampstack-install.yml
- ---
- - name: "LAMP installation for php website"
- hosts: amazon
- become: true
- vars_files:
- - packages.yml
- - apache-group.yml
- tasks:
- - name: "LAMP packages installation"
- yum:
- name: "{{ packages }}"
- state: present
- - name: "httpd service enable"
- service:
- name: httpd
- state: restarted
- enabled: true
- - name: "php service enable"
- service:
- name: php-fpm
- state: restarted
- enabled: true
- - name: "mariadb service enable"
- service:
- name: mariadb
- state: restarted
- enabled: true
- - name: "Copying website to the document root"
- copy:
- src: ./website/
- dest: /var/www/html/
- owner: "{{ httpd_owner }}"
- group: "{{ httpd_group }}"
- [ec2-user@ip-172-31-5-142 ~]$ ansible-playbook -i inventory lampstack-install.yml
- PLAY [LAMP installation for php website] *******************************************************************************
- TASK [Gathering Facts] *************************************************************************************************
- [WARNING]: Platform linux on host 172.31.7.82 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.7.82]
- [WARNING]: Platform linux on host 172.31.5.5 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.5.5]
- TASK [LAMP packages installation] **************************************************************************************
- ok: [172.31.7.82]
- ok: [172.31.5.5]
- TASK [httpd service enable] ********************************************************************************************
- changed: [172.31.7.82]
- changed: [172.31.5.5]
- TASK [php service enable] **********************************************************************************************
- changed: [172.31.7.82]
- changed: [172.31.5.5]
- TASK [mariadb service enable] ******************************************************************************************
- changed: [172.31.5.5]
- changed: [172.31.7.82]
- TASK [Copying website to the document root] ****************************************************************************
- ok: [172.31.5.5]
- ok: [172.31.7.82]
- PLAY RECAP *************************************************************************************************************
- 172.31.5.5 : ok=6 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- 172.31.7.82 : ok=6 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- -------------------------------------------------------------- Task 3 [with_items] -------------------------------------------
- [ec2-user@ip-172-31-5-142 ~]$ cat lampstack-install.yml
- ---
- - name: "LAMP installation for php website"
- hosts: amazon
- become: true
- vars_files:
- - packages.yml
- - apache-group.yml
- tasks:
- - name: "LAMP packages installation"
- yum:
- name: "{{ packages }}"
- state: present
- - name: "httpd,php,mariadb services enable"
- service:
- name: "{{ item }}"
- state: restarted
- enabled: true
- with_items:
- - httpd
- - php-fpm
- - mariadb
- - name: "Copying website to the document root"
- copy:
- src: ./website/
- dest: /var/www/html/
- owner: "{{ httpd_owner }}"
- group: "{{ httpd_group }}"
- [ec2-user@ip-172-31-5-142 ~]$ ansible-playbook -i inventory lampstack-install.yml
- PLAY [LAMP installation for php website] *******************************************************************************
- TASK [Gathering Facts] *************************************************************************************************
- [WARNING]: Platform linux on host 172.31.7.82 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.7.82]
- [WARNING]: Platform linux on host 172.31.5.5 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.5.5]
- TASK [LAMP packages installation] **************************************************************************************
- ok: [172.31.7.82]
- ok: [172.31.5.5]
- TASK [httpd,php,mariadb services enable] *******************************************************************************
- changed: [172.31.7.82] => (item=httpd)
- changed: [172.31.5.5] => (item=httpd)
- changed: [172.31.7.82] => (item=php-fpm)
- changed: [172.31.5.5] => (item=php-fpm)
- changed: [172.31.7.82] => (item=mariadb)
- changed: [172.31.5.5] => (item=mariadb)
- TASK [Copying website to the document root] ****************************************************************************
- ok: [172.31.7.82]
- ok: [172.31.5.5]
- PLAY RECAP *************************************************************************************************************
- 172.31.5.5 : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- 172.31.7.82 : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- -------------------------------- Task 4 [variable declaration for with_items in service module] ---------------------------------------
- #### Declaring directly via vars
- ---
- - name: "LAMP installation for php website"
- hosts: amazon
- become: true
- vars_files:
- - packages.yml
- - apache-group.yml
- vars:
- services:
- - httpd
- - php-fpm
- - mariadb
- tasks:
- - name: "LAMP packages installation"
- yum:
- name: "{{ packages }}"
- state: present
- - name: "httpd,php,mariadb services enable"
- service:
- name: "{{ item }}"
- state: restarted
- enabled: true
- with_items: "{{ services }}"
- - name: "Copying website to the document root"
- copy:
- src: ./website/
- dest: /var/www/html/
- owner: "{{ httpd_owner }}"
- group: "{{ httpd_group }}"
- #### Declaring through vars_files
- [ec2-user@ip-172-31-5-142 ~]$ cat service.yml && echo
- ---
- services:
- - httpd
- - php-fpm
- - mariadb
- [ec2-user@ip-172-31-5-142 ~]$
- [ec2-user@ip-172-31-5-142 ~]$
- [ec2-user@ip-172-31-5-142 ~]$
- [ec2-user@ip-172-31-5-142 ~]$ cat lampstack-install.yml
- ---
- - name: "LAMP installation for php website"
- hosts: amazon
- become: true
- vars_files:
- - packages.yml
- - apache-group.yml
- - service.yml
- tasks:
- - name: "LAMP packages installation"
- yum:
- name: "{{ packages }}"
- state: present
- - name: "httpd,php,mariadb services enable"
- service:
- name: "{{ item }}"
- state: restarted
- enabled: true
- with_items: "{{ services }}"
- - name: "Copying website to the document root"
- copy:
- src: ./website/
- dest: /var/www/html/
- owner: "{{ httpd_owner }}"
- group: "{{ httpd_group }}"
- [ec2-user@ip-172-31-5-142 ~]$ ansible-playbook -i inventory lampstack-install.yml
- PLAY [LAMP installation for php website] *******************************************************************************
- TASK [Gathering Facts] *************************************************************************************************
- [WARNING]: Platform linux on host 172.31.5.5 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.5.5]
- [WARNING]: Platform linux on host 172.31.7.82 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.7.82]
- TASK [LAMP packages installation] **************************************************************************************
- ok: [172.31.5.5]
- ok: [172.31.7.82]
- TASK [httpd,php,mariadb services enable] *******************************************************************************
- changed: [172.31.7.82] => (item=httpd)
- changed: [172.31.5.5] => (item=httpd)
- changed: [172.31.7.82] => (item=php-fpm)
- changed: [172.31.5.5] => (item=php-fpm)
- changed: [172.31.7.82] => (item=mariadb)
- changed: [172.31.5.5] => (item=mariadb)
- TASK [Copying website to the document root] ****************************************************************************
- ok: [172.31.7.82]
- ok: [172.31.5.5]
- PLAY RECAP *************************************************************************************************************
- 172.31.5.5 : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
- 172.31.7.82 : ok=4 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
Advertisement
Add Comment
Please, Sign In to add comment