Commit 0f8901ca authored by Bradon Ladd's avatar Bradon Ladd

Finished Lab 12

parent be8f1c57
Pipeline #21289 waiting for manual action with stage
# lab-12/apache-cgi.yml
# usage:
# ansible-playbook apache-cgi.yml --extra-vars "host=$USER"
---
- hosts: '{{ host }}'
gather_facts: no
become: true
tasks:
- name: Enable the Apache2 module cgi
community.general.apache2_module:
state: present
name: cgid
notify:
- Restart Apache
- name: Install sample CGI program
copy:
src: "files/cgi-hello.py"
dest: "/usr/lib/cgi-bin/cgi-hello.py"
mode: '0755'
handlers:
- name: Restart Apache
service:
name: apache2
state: restarted
#!/usr/bin/env python3
print("Content-type:text/html\r\n\r\n")
print('<html>')
print('<head>')
print('<title>Hello World - Second CGI Program</title>')
print('</head>')
print('<body>')
print('<h2>Hello World! This is my second CGI program</h2>')
print('</body>')
print('</html>')
......@@ -40,3 +40,4 @@ def main():
if __name__ == '__main__':
main()
......@@ -40,3 +40,4 @@ def main():
if __name__ == '__main__':
main()
# lab-12/install-postgresql.yml
# usage:
# ansible-playbook install-postgresql.yml --extra-vars "host=$USER"
---
- hosts: '{{ host }}'
gather_facts: no
become: true
tasks:
- name: Ensure selected locale exists
locale_gen:
name: en_US.UTF-8
state: present
- name: Ensure bash, OpenSSL, libssl, python3, and python3-pip are the latest versions
apt:
name: ['bash', 'openssl', 'libssl-dev', 'libssl-doc', 'python3', 'python3-pip']
update_cache: yes
state: latest
tags: packages
- name: install setfacl support
become: yes
apt: pkg=acl
- name: Install PostgreSQL
apt:
name: ['postgresql', 'postgresql-contrib', 'libpq-dev']
update_cache: no
state: latest
tags: packages
- name: Make sure psycopg2 is installed
pip:
name: psycopg2
state: present
- name: Ensure the PostgreSQL service is running
service: name=postgresql state=started enabled=yes
- name: Ensure database is created
become: true
become_user: postgres
community.postgresql.postgresql_db:
name=cptr245
encoding='UTF-8'
lc_collate='en_US.UTF-8'
lc_ctype='en_US.UTF-8'
template='template0'
state=present
- name: Create web user
become: true
become_user: postgres
community.postgresql.postgresql_user:
db: cptr245
name: www-data
role_attr_flags: SUPERUSER
# lab-12/db-version-1.yml
# usage:
# ansible-playbook version-0-to-1.yml --extra-vars "host=$USER"
---
- hosts: '{{ host }}'
gather_facts: no
become: true
become_user: postgres
tasks:
- name: create DbVersion
community.postgresql.postgresql_table:
db: cptr245
name: DbVersion
columns:
- version integer
- name: set DbVersion
community.postgresql.postgresql_query:
db: cptr245
query: INSERT INTO "DbVersion" SELECT 1 WHERE NOT EXISTS (SELECT * FROM "DbVersion")
- name: create Faculty
community.postgresql.postgresql_table:
db: cptr245
name: Faculty
columns:
- name text
- name: add Aamodt, Larry
community.postgresql.postgresql_query:
db: cptr245
query: INSERT INTO "Faculty" SELECT 'Aamodt, Larry' WHERE NOT EXISTS (SELECT * FROM "Faculty" WHERE name = 'Aamodt, Larry')
- name: add Carman, Preston
community.postgresql.postgresql_query:
db: cptr245
query: INSERT INTO "Faculty" SELECT 'Carman, Preston' WHERE NOT EXISTS (SELECT * FROM "Faculty" WHERE name = 'Carman, Preston')
- name: add Duncan, Jonathan
community.postgresql.postgresql_query:
db: cptr245
query: INSERT INTO "Faculty" SELECT 'Duncan, Jonathan' WHERE NOT EXISTS (SELECT * FROM "Faculty" WHERE name = 'Duncan, Jonathan')
- name: add Foster, James
community.postgresql.postgresql_query:
db: cptr245
query: INSERT INTO "Faculty" SELECT 'Foster, James' WHERE NOT EXISTS (SELECT * FROM "Faculty" WHERE name = 'Foster, James')
- name: Install application version 1
become: true
become_user: root
copy:
src: "files/listFaculty1.py"
dest: "/usr/lib/cgi-bin/listFaculty.py"
mode: "0755"
# lab-12/version-1-to-2.yml
# usage:
# ansible-playbook version-1-to-2.yml --extra-vars "host=$USER"
---
- hosts: '{{ host }}'
gather_facts: no
become: true
become_user: postgres
tasks:
- name: get database version
community.postgresql.postgresql_query:
db: cptr245
query: SELECT version FROM "DbVersion"
register: RESULT
- name: add lastName column
community.postgresql.postgresql_query:
db: cptr245
query: ALTER TABLE "Faculty" ADD COLUMN lastName text;
when: "RESULT.query_result[0].version == 1"
- name: add firstName colum
community.postgresql.postgresql_query:
db: cptr245
query: ALTER TABLE "Faculty" ADD COLUMN firstName text;
when: "RESULT.query_result[0].version == 1"
- name: Split last name
community.postgresql.postgresql_query:
db: cptr245
query: UPDATE "Faculty" SET lastName = split_part(name, ', ', 1);
when: "RESULT.query_result[0].version == 1"
- name: Split last name
community.postgresql.postgresql_query:
db: cptr245
query: UPDATE "Faculty" SET firstName = split_part(name, ', ', 2);
when: "RESULT.query_result[0].version == 1"
- name: Drop Column "name"
community.postgresql.postgresql_query:
db: cptr245
query: ALTER TABLE "Faculty" DROP COLUMN name;
when: "RESULT.query_result[0].version == 1"
- name: Install application version 2
become: true
become_user: root
copy:
src: "files/listFaculty2.py"
dest: "/usr/lib/cgi-bin/listFaculty.py"
mode: "0755"
when: "RESULT.query_result[0].version == 1"
- name: Set DbVersion to 2
community.postgresql.postgresql_query:
db: cptr245
query: UPDATE "DbVersion" SET version = 2;
when: "RESULT.query_result[0].version == 1"
# lab-12/version-2-to-1.yml
# usage:
# ansible-playbook version-2-to-1.yml --extra-vars "host=$USER"
---
- hosts: '{{ host }}'
gather_facts: no
become: true
become_user: postgres
tasks:
- name: get database version
community.postgresql.postgresql_query:
db: cptr245
query: SELECT version FROM "DbVersion"
register: RESULT
- name: Re-add "name" column
community.postgresql.postgresql_query:
db: cptr245
query: ALTER TABLE "Faculty" ADD COLUMN name text;
when: "RESULT.query_result[0].version == 2"
- name: Concanenate columns
community.postgresql.postgresql_query:
db: cptr245
query: UPDATE "Faculty" SET name = CONCAT(firstName, ',', lastName);
when: "RESULT.query_result[0].version == 2"
- name: Remove lastname
community.postgresql.postgresql_query:
db: cptr245
query: ALTER TABLE "Faculty" DROP COLUMN lastname;
when: "RESULT.query_result[0].version == 2"
- name: Remove firstname
community.postgresql.postgresql_query:
db: cptr245
query: ALTER TABLE "Faculty" DROP COLUMN firstname;
when: "RESULT.query_result[0].version == 2"
- name: Install application version 1
become: true
become_user: root
copy:
src: "files/listFaculty1.py"
dest: "/usr/lib/cgi-bin/listFaculty.py"
mode: "0755"
when: "RESULT.query_result[0].version == 2"
- name: Set DbVersion to 1
community.postgresql.postgresql_query:
db: cptr245
query: UPDATE "DbVersion" SET version = 1;
when: "RESULT.query_result[0].version == 2"
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment