diff --git a/lotus-land-story/README.md b/lotus-land-story/README.md index 824daf6..2dfdeee 100644 --- a/lotus-land-story/README.md +++ b/lotus-land-story/README.md @@ -1,5 +1,14 @@ # Lotus Land Story ``` +# create the linode instance terraform apply + +# add the IP to ~/.ssh/config + +# make sure we can hit it +ansible all -m ping + +# run ansible +ansible-playbook main.yml ``` diff --git a/lotus-land-story/ansible.cfg b/lotus-land-story/ansible.cfg new file mode 100644 index 0000000..fb5de8d --- /dev/null +++ b/lotus-land-story/ansible.cfg @@ -0,0 +1,2 @@ +[defaults] +inventory=hosts.yml diff --git a/lotus-land-story/hosts.yml b/lotus-land-story/hosts.yml new file mode 100644 index 0000000..aa4a4bb --- /dev/null +++ b/lotus-land-story/hosts.yml @@ -0,0 +1,3 @@ +all: + hosts: + lotus-land-story: diff --git a/lotus-land-story/main.yml b/lotus-land-story/main.yml new file mode 100644 index 0000000..229baba --- /dev/null +++ b/lotus-land-story/main.yml @@ -0,0 +1,124 @@ +- name: Set up lotus-land-story + hosts: lotus-land-story + tasks: + + # https://wiki.debian.org/PostgreSql + - name: Install postgres + ansible.builtin.apt: + pkg: + - postgresql + - postgresql-client + state: present + + - name: Install ansible requirements + ansible.builtin.apt: + pkg: + - docker-compose + - libpq-dev + - python3-docker + - python3-psycopg2 + state: present + + # https://docs.docker.com/engine/install/debian/#install-using-the-repository + - name: Install docker + block: + - name: Install docker requirements + ansible.builtin.apt: + pkg: + - ca-certificates + - curl + - gnupg + state: present + - name: Make /etc/apt/keyrings + file: + path: /etc/apt/keyrings + state: directory + mode: 0755 + - name: Download Docker GPG key + ansible.builtin.shell: curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + args: + creates: /etc/apt/keyrings/docker.gpg + - name: Get architecture + command: dpkg --print-architecture + register: arch + - name: Set up docker repository + ansible.builtin.template: + src: templates/docker.list + dest: /etc/apt/sources.list.d/docker.list + - name: Install docker + apt: + pkg: + - docker-ce + - docker-ce-cli + - containerd.io + - docker-buildx-plugin + - docker-compose-plugin + update_cache: true + + - name: Set up postgres + become: true + become_user: postgres + block: + + # https://miniflux.app/docs/installation.html#docker + - name: Create a miniflux db + community.postgresql.postgresql_db: + name: miniflux + notify: Restart postgres + - name: Create a miniflux db user + community.postgresql.postgresql_user: + db: miniflux + name: miniflux + password: miniflux + notify: Restart postgres + - name: Get docker0 IP address + ansible.builtin.shell: ip -4 -o addr show docker0 | awk '{print $4}' + register: docker_ip + - name: Listen on docker0 interface + ansible.builtin.lineinfile: + dest: "/etc/postgresql/13/main/conf.d/listen.conf" + regexp: '^#?listen_addresses=' + line: "listen_addresses='localhost,{{ docker_ip.stdout | ansible.utils.ipaddr('address') }}'" + state: present + create: true + notify: Restart postgres + - name: Grant miniflux access + community.postgresql.postgresql_pg_hba: + dest: /etc/postgresql/13/main/pg_hba.conf + contype: host + users: miniflux + source: samenet + databases: miniflux + create: true + notify: Restart postgres + + - name: Install extensions + community.postgresql.postgresql_ext: + name: hstore + db: miniflux + notify: Restart postgres + + - name: Run miniflux + community.docker.docker_compose: + project_name: miniflux + definition: + version: "3.3" + services: + miniflux: + image: miniflux/miniflux:latest + ports: + - "80:8080" + environment: + - DATABASE_URL=postgres://miniflux:miniflux@host.docker.internal/miniflux + - RUN_MIGRATIONS=1 + - CREATE_ADMIN=1 + - ADMIN_USERNAME=admin + - ADMIN_PASSWORD=test123 + extra_hosts: + - "host.docker.internal:host-gateway" + + handlers: + - name: Restart postgres + ansible.builtin.service: + name: postgresql + state: restarted diff --git a/lotus-land-story/templates/docker.list b/lotus-land-story/templates/docker.list new file mode 100644 index 0000000..8840d81 --- /dev/null +++ b/lotus-land-story/templates/docker.list @@ -0,0 +1 @@ +deb [arch="{{ arch.stdout }}" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable