Skip to content

Commit

Permalink
Add windows scoop
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyao9184 committed Sep 1, 2024
1 parent ae5cbf9 commit c8a8312
Show file tree
Hide file tree
Showing 11 changed files with 267 additions and 0 deletions.
26 changes: 26 additions & 0 deletions windows/scoop/ansible-playbook.script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env -S ansible-playbook -i ${PWD}/ansible-inventories
# code: language=ansible
---

- name: script
vars:
ansible_connection: local
hosts: windows
connection: local
tasks:

- name: mkdir script
delegate_to: localhost
connection: local
ansible.builtin.file:
state: directory
path: "{{ inventory_dir }}/../scoop/{{ inventory_hostname }}"

- name: template script
delegate_to: localhost
connection: local
ansible.builtin.template:
src: "{{ playbook_dir }}/scoop.install.ps1.j2"
dest: "{{ inventory_dir }}/../scoop/{{ inventory_hostname }}/scoop.install.ps1"
register: package_install_template

34 changes: 34 additions & 0 deletions windows/scoop/bucket/ansible-playbook.install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env -S ansible-playbook -k -i ${PWD}/ansible-inventories
# code: language=ansible
---

- name: install
hosts: windows
tasks:

- name: install bucket
loop: "{{ scoop.buckets | default([],true) }}"
vars:
combine:
state: present
args: "{{ item | combine(combine, recursive=True) }}"
community.windows.win_scoop_bucket: "{{ args }}"
register: bucket_install
until: bucket_install is succeeded

- name: install group config
vars:
group_names: "{{ scoop.groups | default([],true) }}"
group_vars: "{{ scoop_groups | default({},true)
| dict2items
| selectattr('key','in',group_names)
| selectattr('value.buckets','defined')
| map(attribute='value.buckets')
| flatten }}"
combine:
state: present
args: "{{ item | combine(combine, recursive=True) }}"
loop: "{{ group_vars }}"
community.windows.win_scoop_bucket: "{{ args }}"
register: bucket_install
until: bucket_install is succeeded
40 changes: 40 additions & 0 deletions windows/scoop/bucket/ansible-playbook.script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env -S ansible-playbook -i ${PWD}/ansible-inventories
# code: language=ansible
---

- name: script
vars:
ansible_connection: local
hosts: windows
connection: local
tasks:

- name: mkdir script
delegate_to: localhost
connection: local
ansible.builtin.file:
state: directory
path: "{{ inventory_dir }}/../scoop/{{ inventory_hostname }}"

- name: template install buckets script
delegate_to: localhost
connection: local
vars:
group_names: "{{ scoop.groups | default([],true) }}"
group_vars: "{{ scoop_groups | default({},true)
| dict2items
| selectattr('key','in',group_names)
| selectattr('value.buckets','defined')
| rejectattr('value.buckets','equalto',None) }}"
group_buckets_all:
- group: default
buckets: "{{ scoop.buckets | default([],true) }}"
- "{{ group_vars
| community.general.json_query('[].{group:key,buckets:value.buckets}') }}"
configs: "{{ group_buckets_all | flatten }}"
buckets: "{{ item.buckets }}"
loop: "{{ configs }}"
ansible.builtin.template:
src: "{{ playbook_dir }}/bucket.install.ps1.j2"
dest: "{{ inventory_dir }}/../scoop/{{ inventory_hostname }}/{{ item.group }}.bucket.install.ps1"
register: bucket_install_template
5 changes: 5 additions & 0 deletions windows/scoop/bucket/bucket.install.ps1.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$_script_dir = Split-Path -parent $MyInvocation.MyCommand.Definition

{% for bucket in buckets %}
scoop bucket add {{ bucket.name }}
{% endfor %}
40 changes: 40 additions & 0 deletions windows/scoop/config/ansible-playbook.script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env -S ansible-playbook -i ${PWD}/ansible-inventories
# code: language=ansible
---

- name: script
vars:
ansible_connection: local
hosts: windows
connection: local
tasks:

- name: mkdir script
delegate_to: localhost
connection: local
ansible.builtin.file:
state: directory
path: "{{ inventory_dir }}/../scoop/{{ inventory_hostname }}"

- name: template install configs script
delegate_to: localhost
connection: local
vars:
group_names: "{{ scoop.groups | default([],true) }}"
group_vars: "{{ scoop_groups | default({},true)
| dict2items
| selectattr('key','in',group_names)
| selectattr('value.configs','defined')
| rejectattr('value.configs','equalto',None) }}"
group_vars_all:
- group: default
configs: "{{ scoop.configs | default([],true) }}"
- "{{ group_vars
| community.general.json_query('[].{group:key,configs:value.configs}') }}"
group_vars_flatten: "{{ group_vars_all | flatten }}"
configs: "{{ item.configs }}"
loop: "{{ group_vars_flatten }}"
ansible.builtin.template:
src: "{{ playbook_dir }}/config.set.ps1.j2"
dest: "{{ inventory_dir }}/../scoop/{{ inventory_hostname }}/{{ item.group }}.config.set.ps1"
register: config_set_template
36 changes: 36 additions & 0 deletions windows/scoop/config/ansible-playbook.set.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env -S ansible-playbook -k -i ${PWD}/ansible-inventories
# code: language=ansible
---

- name: set
hosts: windows
tasks:

- name: set config
loop: "{{ scoop.configs | default([],true) }}"
vars:
combine:
state: present
args: "{{ item | combine(combine, recursive=True) }}"
ansible.windows.win_powershell:
script: scoop config {{ args.name }} {{ args.value }}
register: config_set
until: config_set is succeeded

- name: set group config
vars:
group_names: "{{ scoop.groups | default([],true) }}"
group_vars: "{{ scoop_groups | default({},true)
| dict2items
| selectattr('key','in',group_names)
| selectattr('value.configs','defined')
| map(attribute='value.configs')
| flatten }}"
combine:
state: present
args: "{{ item | combine(combine, recursive=True) }}"
loop: "{{ group_vars }}"
ansible.windows.win_powershell:
script: scoop config {{ args.name }} {{ args.value }}
register: config_set
until: config_set is succeeded
5 changes: 5 additions & 0 deletions windows/scoop/config/config.set.ps1.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$_script_dir = Split-Path -parent $MyInvocation.MyCommand.Definition

{% for config in configs %}
scoop config {{ config.name }} {{ config.value }}
{% endfor %}
34 changes: 34 additions & 0 deletions windows/scoop/package/ansible-playbook.install.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env -S ansible-playbook -k -i ${PWD}/ansible-inventories
# code: language=ansible
---

- name: install
hosts: windows
tasks:

- name: install package
loop: "{{ scoop.packages | default([],true) }}"
vars:
combine:
state: present
args: "{{ item | combine(combine, recursive=True) }}"
community.windows.win_scoop: "{{ args }}"
register: package_install
until: package_install is succeeded

- name: install group config
vars:
group_names: "{{ scoop.groups | default([],true) }}"
group_vars: "{{ scoop_groups | default({},true)
| dict2items
| selectattr('key','in',group_names)
| selectattr('value.packages','defined')
| map(attribute='value.packages')
| flatten }}"
combine:
state: present
args: "{{ item | combine(combine, recursive=True) }}"
loop: "{{ group_vars }}"
community.windows.win_scoop: "{{ args }}"
register: package_install
until: package_install is succeeded
40 changes: 40 additions & 0 deletions windows/scoop/package/ansible-playbook.script.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env -S ansible-playbook -i ${PWD}/ansible-inventories
# code: language=ansible
---

- name: script
vars:
ansible_connection: local
hosts: windows
connection: local
tasks:

- name: mkdir script
delegate_to: localhost
connection: local
ansible.builtin.file:
state: directory
path: "{{ inventory_dir }}/../scoop/{{ inventory_hostname }}"

- name: template install packages script
delegate_to: localhost
connection: local
vars:
group_names: "{{ scoop.groups | default([],true) }}"
group_vars: "{{ scoop_groups | default({},true)
| dict2items
| selectattr('key','in',group_names)
| selectattr('value.packages','defined')
| rejectattr('value.packages','equalto',None) }}"
group_packages_all:
- group: default
packages: "{{ scoop.packages | default([],true) }}"
- "{{ group_vars
| community.general.json_query('[].{group:key,packages:value.packages}') }}"
configs: "{{ group_packages_all | flatten }}"
packages: "{{ item.packages }}"
loop: "{{ configs }}"
ansible.builtin.template:
src: "{{ playbook_dir }}/package.install.ps1.j2"
dest: "{{ inventory_dir }}/../scoop/{{ inventory_hostname }}/{{ item.group }}.package.install.ps1"
register: package_install_template
5 changes: 5 additions & 0 deletions windows/scoop/package/package.install.ps1.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
$_script_dir = Split-Path -parent $MyInvocation.MyCommand.Definition

{% for package in packages %}
scoop install {{ package.name }}
{% endfor %}
2 changes: 2 additions & 0 deletions windows/scoop/scoop.install.ps1.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression

0 comments on commit c8a8312

Please sign in to comment.