Skip to content

Commit 943dd0f

Browse files
authored
chore(ansible): update ansible (#137)
* chore: add backup functionality to config items - Updated .gitignore to exclude backup directory. - Added tasks to backup config items before removal in all.yml. - Introduced backup directory setup in main.yml. * chore(ansible): update configuration and host settings - Added new settings in ansible.cfg for host key checking, fact caching, and pipelining. - Modified hosts.yml to streamline localhost configuration and remove unnecessary nesting. - Updated localhost.yml to disable fact gathering and set the strategy to free. * chore(vscode): remove deprecated extensions file and update installation task - Deleted the obsolete extensions file from the configuration. - Updated the installation task to read from the new extensions.txt file instead of the removed extensions file. * chore(ansible): enhance configuration tasks for home directories - Added tasks to process files for .config and .local/share directories. - Introduced handling for direct home files, including backup and removal tasks. - Updated existing tasks to improve clarity and functionality. * chore(ansible): refine localhost configuration and enhance file handling - Removed the lock file from the ansible directory. - Updated localhost.yml to set gather_facts to false. - Added file mode setting for copied files in all.yml to ensure proper permissions.
1 parent 8377d9f commit 943dd0f

File tree

10 files changed

+65
-13
lines changed

10 files changed

+65
-13
lines changed

.ansible/.lock

Whitespace-only changes.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
/backup/
12
*.log

scripts/ansible/ansible.cfg

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
[defaults]
22
executable = /bin/bash
3+
host_key_checking = False
4+
gathering = smart
5+
fact_caching = memory
6+
fact_caching_timeout = 86400
7+
pipelining = True
8+
forks = 10
39

410
[ssh_connection]
511
ssh_args = -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
12+
pipelining = True

scripts/ansible/hosts.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
---
21
all:
32
vars:
43
ansible_user: ansible_user
54
ansible_python_interpreter: /usr/bin/python3
65
children:
76
localhost:
8-
children:
7+
hosts:
98
localhost:
10-
hosts:
11-
localhost:
9+
ansible_connection: local
10+
ansible_python_interpreter: "{{ ansible_playbook_python }}"

scripts/ansible/localhost.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
- name: Localhost
22
hosts: localhost
33
connection: local
4+
gather_facts: false
45
roles:
56
- role: set_facts
67
tags:

scripts/ansible/roles/config/tasks/all.yml

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,37 @@
1717
ansible.builtin.set_fact:
1818
config_paths: "{{ config_files.files | map(attribute='path') | map('replace', vars.config_dir + '/', '') | list }}"
1919

20-
- name: Transform matched paths
20+
- name: Get config items (.config and .local/share patterns)
2121
ansible.builtin.set_fact:
2222
config_items: "{{ config_paths | select('match', '.*(' + replace_list | join('|') + ')') | list }}"
2323

24-
- name: Transform paths using patterns
24+
- name: Transform config paths using patterns
2525
ansible.builtin.set_fact:
2626
config_items: "{{ config_items | map('regex_replace', '^([^/]+)/' + item | regex_escape + '/(.*)$', item + '/\\1/\\2') | list }}"
2727
loop: "{{ replace_list }}"
2828

29-
- name: Remove unwanted paths
29+
- name: Remove unwanted config paths
3030
ansible.builtin.set_fact:
3131
config_items: "{{ config_items | reject('match', '.*(' + dir_symlinks | join('|') + ')') | list }}"
3232

3333
- name: Check config_items files
3434
ansible.builtin.stat:
35-
path: "{{ item }}"
35+
path: "~/{{ item }}"
3636
with_items: "{{ vars.config_items }}"
3737
register: check_config_items
3838

39+
- name: Backup config_items files
40+
ansible.builtin.copy:
41+
src: "{{ item.stat.path }}"
42+
dest: "{{ vars.backup_dir }}/{{ item.stat.path }}"
43+
mode: "0644"
44+
with_items: "{{ check_config_items.results | selectattr('stat.exists') | selectattr('stat.islnk', 'equalto', false) | list }}"
45+
3946
- name: Remove config_items files
4047
ansible.builtin.file:
4148
path: "{{ item.stat.path }}"
4249
state: absent
43-
when: item.stat.exists and not item.stat.islnk
44-
with_items: "{{ check_config_items.results }}"
50+
with_items: "{{ check_config_items.results | selectattr('stat.exists') | selectattr('stat.islnk', 'equalto', false) | list }}"
4551

4652
- name: Mkdir config paths
4753
ansible.builtin.file:
@@ -56,3 +62,33 @@
5662
dest: "~/{{ item }}"
5763
state: link
5864
with_items: "{{ vars.config_items }}"
65+
66+
- name: Get direct home files from config directories
67+
ansible.builtin.set_fact:
68+
direct_home_files: "{{ config_paths | select('match', '^[^/]+/[^/]+$') | reject('match', '.*(' + replace_list | join('|') + ')') | list }}"
69+
70+
- name: Check direct home files
71+
ansible.builtin.stat:
72+
path: "~/{{ item | regex_replace('^[^/]+/', '') }}"
73+
with_items: "{{ vars.direct_home_files }}"
74+
register: check_direct_home_files
75+
76+
- name: Backup direct home files
77+
ansible.builtin.copy:
78+
src: "{{ item.stat.path }}"
79+
dest: "{{ vars.backup_dir }}/{{ item.stat.path }}"
80+
mode: "0644"
81+
with_items: "{{ check_direct_home_files.results | selectattr('stat.exists') | selectattr('stat.islnk', 'equalto', false) | list }}"
82+
83+
- name: Remove direct home files
84+
ansible.builtin.file:
85+
path: "{{ item.stat.path }}"
86+
state: absent
87+
with_items: "{{ check_direct_home_files.results | selectattr('stat.exists') | selectattr('stat.islnk', 'equalto', false) | list }}"
88+
89+
- name: Make direct home symlinks
90+
ansible.builtin.file:
91+
src: "{{ vars.config_dir }}/{{ item }}"
92+
dest: "~/{{ item | regex_replace('^[^/]+/', '') }}"
93+
state: link
94+
with_items: "{{ vars.direct_home_files }}"

scripts/ansible/roles/config/tasks/zsh.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
- name: Check zsh files in ~/
32
ansible.builtin.stat:
43
path: "{{ item | replace(vars.config_dir + '/zsh/', '~/') }}"

scripts/ansible/roles/set_facts/tasks/main.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
---
21
- name: Get home dir
32
ansible.builtin.command:
43
cmd: echo ~
@@ -17,3 +16,13 @@
1716
- name: Set config dir
1817
ansible.builtin.set_fact:
1918
config_dir: "{{ vars.dotfiles_dir }}/config"
19+
20+
- name: Set backup dir
21+
ansible.builtin.set_fact:
22+
backup_dir: "{{ vars.dotfiles_dir }}/backup"
23+
24+
- name: Make backup dir
25+
ansible.builtin.file:
26+
path: "{{ vars.backup_dir }}"
27+
state: directory
28+
mode: "0755"

scripts/ansible/roles/vscode/tasks/install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
- name: Install vscode extensions
77
ansible.builtin.command: "{{ code_command }} --install-extension {{ item }}"
8-
with_lines: cat {{ vars.config_dir }}/vscode/extensions
8+
with_lines: cat {{ vars.config_dir }}/vscode/data/extensions.txt
99
changed_when: true
1010
when: item not in vscode_extensions.stdout_lines and item != ''

0 commit comments

Comments
 (0)