diff --git a/docker-server.yml b/docker-server.yml index 75bd75c..e92fd6f 100644 --- a/docker-server.yml +++ b/docker-server.yml @@ -1,12 +1,12 @@ --- - hosts: docker become: true - roles: - - role: common - vars: - common_deploy_public_key: "/home/andreas/git_repos/projects/tintenwelt/keys/ansible.pub" - - common-server - - restic + # roles: + # - role: common + # vars: + # common_deploy_public_key: "/home/andreas/git_repos/projects/tintenwelt/keys/ansible.pub" + # - common-server + # - restic tasks: - import_tasks: tasks/main.yml vars_files: diff --git a/tasks/main.yml b/tasks/main.yml index 111a8ac..12caa46 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,15 +5,33 @@ when: - ansible_facts['distribution'] == "Ubuntu" -- name: "Add apt key for Docker" +- name: "Add apt key for Ubuntu Docker" apt_key: url: "https://download.docker.com/linux/ubuntu/gpg" state: present + when: + - ansible_facts['distribution'] == "Ubuntu" -- name: "Add Docker repository" +- name: "Add Docker Ubuntu repository" apt_repository: - repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" + repo: "deb [arch=amd64] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable" state: present + when: + - ansible_facts['distribution'] == "Ubuntu" + +- name: "Add apt key for Debian Docker" + apt_key: + url: "https://download.docker.com/linux/debian/gpg" + state: present + when: + - ansible_facts['distribution'] == "Debian" + +- name: "Add Docker Debian repository" + apt_repository: + repo: "deb [arch=amd64] https://download.docker.com/linux/debian {{ ansible_distribution_release }} stable" + state: present + when: + - ansible_facts['distribution'] == "Debian" - name: "Install Docker" apt: @@ -42,24 +60,26 @@ - name: "Get the Systems repository" ansible.builtin.git: repo: "https://git.2li.ch/Nebucatnetzer/docker_systems.git" - dest: "{{ lookup('env', 'HOME') }}/docker_systems" + dest: "/home/{{ ansible_ssh_user }}/docker_systems" become: no when: docker_skip_project is undefined - name: "Get the .env template" ansible.builtin.fetch: - src: "{{ docker_project_path }}/.env.example" - dest: "/tmp/fetched/{{ inventory_hostname }}.env.example" + src: "{{ docker_project_path }}/.env.j2" + dest: "/tmp/fetched/{{ inventory_hostname }}.env.j2" flat: yes + fail_on_missing: no + register: env_file become: no when: docker_skip_project is undefined - name: "Copy the .env file" ansible.builtin.template: - src: "/tmp/fetched/{{ inventory_hostname }}.env.example" + src: "/tmp/fetched/{{ inventory_hostname }}.env.j2" dest: "{{ docker_project_path }}/.env" become: no - when: docker_skip_project is undefined + when: docker_skip_project is undefined and env_file.changed - name: "Open the required UDP ports" ansible.builtin.ufw: diff --git a/vars/main.yml b/vars/main.yml index 075fbe5..96f88b4 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,2 @@ docker_lazydocker_version: 0.12 -docker_project_path: "{{ lookup('env', 'HOME') }}/docker_systems/{{ docker_project_name }}" +docker_project_path: "/home/{{ ansible_ssh_user }}/docker_systems/{{ docker_project_name }}"