diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..f898e74 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "cSpell.words": [ + "domainname", + "portainer" + ] +} \ No newline at end of file diff --git a/defaults/main.yml b/defaults/main.yml index cc29741..a134ef6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,4 +1,6 @@ --- # defaults file for ansible-clean-vagrant -# TODO: Add the necessary variables +server_host: none +portainer_config: /tmp/config +portainer_port: "8000" diff --git a/molecule/default/converge.yml b/molecule/default/converge.yml index cc0749b..d71ca72 100644 --- a/molecule/default/converge.yml +++ b/molecule/default/converge.yml @@ -4,7 +4,9 @@ hosts: all become: true # Set default variables (if any) - vars: [] + vars: + server_host: "portainer-server" + domain_suffix: "laurii.lan" # Use pre_tasks when you need a setup to be executed each time you run converge. # Otherwise, 'prepare.yml' is the way to go @@ -15,5 +17,5 @@ # name: "docker_repository" roles: - - role: ansible-clean-vagrant + - role: docker.portainer become: true diff --git a/molecule/default/molecule.yml b/molecule/default/molecule.yml index 94eb976..3fac031 100644 --- a/molecule/default/molecule.yml +++ b/molecule/default/molecule.yml @@ -8,14 +8,24 @@ driver: provider: name: virtualbox platforms: - - name: ubuntu-2004 + - name: portainer-server box: generic/ubuntu2004 memory: 8192 cpus: 4 instance_raw_config_args: # Forward the necessary ports for your app (if any) # - - "vm.network 'forwarded_port', guest: 1880, host: 1880" + - "vm.network 'forwarded_port', guest: 8000, host: 8000" + - "vm.network 'forwarded_port', guest: 9000, host: 9000" + + - name: portainer-agent + box: generic/ubuntu2004 + memory: 8192 + cpus: 4 + instance_raw_config_args: + # Forward the necessary ports for your app (if any) + # + - "vm.network 'forwarded_port', guest: 9001, host: 9001" provisioner: name: ansible diff --git a/molecule/default/prepare.yml b/molecule/default/prepare.yml index a11a219..654f9a7 100644 --- a/molecule/default/prepare.yml +++ b/molecule/default/prepare.yml @@ -11,8 +11,11 @@ apt: name: ansible state: present + autoclean: yes + autoremove: yes + update_cache: yes become: true - + # Install docker (and update repos) # - name: "Set up docker on the machine" diff --git a/tasks/main.yml b/tasks/main.yml index a3e93dc..67ab86a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,49 @@ --- -# tasks file for ansible_role +# tasks file for portainer role + +# +# Install portainer server on the server host +# +- name: Skip server installation + debug: + msg: "Skip server installation because server_host is {{ server_host }}" + when: server_host == "none" + +# +# Install portainer server on the server host +# +- name: Install server + docker_container: + name: "portainer_{{ inventory_hostname }}" + hostname: "portainer_{{ inventory_hostname}}" + domainname: "{{ domain_suffix }}" + image: "portainer/portainer-ce" + recreate: yes + restart: yes + restart_policy: "always" + ports: + - "{{ portainer_port}}:8000" + - "9000:9000" + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + - "{{ portainer_config }}:/data" + when: inventory_hostname == server_host and server_host and server_host != "none" + +# +# Install portainer server on the server host +# +- name: Install agent + docker_container: + name: "portainer_agent_{{ inventory_hostname }}" + hostname: "portainer_agent_{{ inventory_hostname}}" + domainname: "{{ domain_suffix }}" + image: "portainer/agent" + recreate: yes + restart: yes + restart_policy: "always" + ports: + - "9001:9001" + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + - "/var/lib/docker/volumes:/var/lib/docker/volumes" + when: inventory_hostname != server_host and server_host \ No newline at end of file