diff --git a/defaults.yml b/defaults.yml new file mode 100644 index 0000000..184975d --- /dev/null +++ b/defaults.yml @@ -0,0 +1,15 @@ +# containers during host setup +container_names: + - dev + - txt + - haskell + +# containers tool groups +container_tools: + dev: + - cpp + - js + txt: + - txt + haskell: + - haskell diff --git a/playbooks/box.yml b/playbooks/box.yml index 13a9df5..da77359 100644 --- a/playbooks/box.yml +++ b/playbooks/box.yml @@ -1,26 +1,30 @@ -- name: Install all required tools into the distrobox dev container +- name: Configure distrobox dev container hosts: localhost connection: local vars: - configue: - - bash - - cli - - git - - ssh - - scripts - apps: - - cli - # tools: - # - cpp - # - javascript vars_prompt: - name: tools_in prompt: "Specify comma separated list of required tool packages (cpp, js, haskell, txt, lang)" - pre_tasks: - - ansible.builtin.set_fact: - tools: "{{ tools_in.split(',') }}" roles: + # link and copy dotfiles - role: dotfiles + vars: + configue: + - bash + - cli + - git + - ssh + - scripts + + # install apps - role: installs + vars: + apps: + - cli + + # install and setup dev tools - role: dev + vars: + tools: "{{ tools_in.split(',') }}" + # TODO: repositories diff --git a/playbooks/host.yml b/playbooks/host.yml index 8b13789..bc3599a 100644 --- a/playbooks/host.yml +++ b/playbooks/host.yml @@ -1 +1,38 @@ +- name: Create distrobox containers on host + hosts: localhost + connection: local + vars: + tasks: + - name: Create containers + include_role: + name: dev_host + vars: + container_name: '{{ item }}' + loop: '{{ container_names }}' +- name: Setup containers + hosts: containers + roles: + # link and copy dotfiles + - role: dotfiles + vars: + configue: + - bash + - cli + - git + - ssh + - scripts + + # install apps + - role: installs + vars: + apps: + - cli + + # install and setup dev tools + - role: dev + vars: + tools: "{{ container_tools['{{item}}'] }}" + + # TODO: repositories + diff --git a/roles/dev_host/defaults/main.yml b/roles/dev_host/defaults/main.yml new file mode 100644 index 0000000..e7acdef --- /dev/null +++ b/roles/dev_host/defaults/main.yml @@ -0,0 +1,3 @@ +container_name: dev +container_image: quay.io/fedora/fedora-toolbox +container_image_tag: latest diff --git a/roles/dev_host/tasks/main.yml b/roles/dev_host/tasks/main.yml new file mode 100644 index 0000000..382884e --- /dev/null +++ b/roles/dev_host/tasks/main.yml @@ -0,0 +1,37 @@ +# os based on https://github.com/sandorex/config/blob/master/playbooks/container-dev.yml + +- name: Check if container already exists + containers.podman.podman_container_info: + name: '{{ container_name }}' + register: container_info + +- name: Create container using distrobox + ansible.builtin.command: + # requires distrobox version 1.7 + # add python3 to allow ansible to work + # add ansible to run local roles without host (?) + cmd: >- + distrobox create --yes --no-entry --pull + --image '{{ container_image }}:{{ container_image_tag }}' + --name '{{ container_name }}' + --hostname '{{ ansible_hostname }}' + --additional-packages 'python3 ansible' + when: container_info.containers | length == 0 + +- name: Start the container + ansible.builtin.command: + cmd: 'distrobox enter --name {{ container_name }} -- sh -c ''exit''' + # start if not running or if not defined + when: not (container_info.containers[0].State.Running | default(false)) + +- name: Add container to host + changed_when: no + ansible.builtin.add_host: + name: '{{ container_name }}' # ?? + groups: containers + ansible_connection: distrobox + ansible_host: '{{ container_name }}' + ansible_user: '{{ ansible_user_id }}' + fedora_version: '{{ container_image_tag }}' # ?? + +# container setup is done outside (?)