Skip to content

Commit

Permalink
Added ability to write settings.json (#33)
Browse files Browse the repository at this point in the history
Write the `settings.json` for the user based on configuration supplied in the playbook.

Enhancement: resolves #32
  • Loading branch information
freemanjp authored Aug 29, 2016
1 parent ee42b3c commit be401f9
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ users:
visual_studio_code_extensions:
- # extension 1
- # extension 2
visual_studio_code_settings: # JSON object
```
### Supported Visual Studio Code Versions
Expand Down Expand Up @@ -88,6 +89,13 @@ Playbook with extensions installed:
- streetsidesoftware.code-spell-checker
- wholroyd.jinja
- donjayamanne.python
visual_studio_code_settings: {
"editor.rulers": [80, 100, 120],
"editor.renderWhitespace": true,
"files.associations": {
"Vagrantfile": "ruby"
}
}
```

More Roles From GantSign
Expand Down
2 changes: 2 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
- include: install.yml

- include: install-extensions.yml

- include: write-settings.yml
22 changes: 22 additions & 0 deletions tasks/write-settings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
- name: create settings directory
become: yes
file:
path: '~{{ item.username }}/.config/Code/User'
state: directory
owner: '{{ item.username }}'
group: '{{ item.username }}'
mode: 'u=rwx,go='
with_items: '{{ users }}'

- name: write settings
become: yes
template:
src: settings.json.j2
dest: '~{{ item.username }}/.config/Code/User/settings.json'
force: no
owner: '{{ item.username }}'
group: '{{ item.username }}'
mode: 'u=rw,go='
with_items: '{{ users }}'
when: "item.visual_studio_code_settings is defined and item.visual_studio_code_settings not in ({}, '', None, omit)"
2 changes: 2 additions & 0 deletions templates/settings.json.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Place your settings in this file to overwrite the default settings
{{ item.visual_studio_code_settings | to_nice_json }}
22 changes: 22 additions & 0 deletions tests/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
state: present
home: /home/test_usr
createhome: yes
- name: create test_usr2
become: yes
user:
name: test_usr2
state: present
home: /home/test_usr2
createhome: yes
- name: create test_usr3
become: yes
user:
name: test_usr3
state: present
home: /home/test_usr3
createhome: yes

roles:
- role: ansible-role-visual-studio-code
Expand All @@ -18,6 +32,14 @@
visual_studio_code_extensions:
- donjayamanne.python
- wholroyd.jinja
visual_studio_code_settings: {
"editor.rulers": [80, 100, 120],
"editor.renderWhitespace": true,
"files.associations": {
"Vagrantfile": "ruby"
}
}
- username: test_usr2
visual_studio_code_extensions: []
visual_studio_code_settings: {}
- username: test_usr3
14 changes: 14 additions & 0 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from testinfra.utils.ansible_runner import AnsibleRunner

testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')


def test_settings(File):
settings_file = File('/home/test_usr/.config/Code/User/settings.json')

assert settings_file.exists
assert settings_file.is_file
assert settings_file.user == 'test_usr'
assert settings_file.group == 'test_usr'
assert oct(settings_file.mode) == '0600'
assert settings_file.contains('"Vagrantfile": "ruby"')

0 comments on commit be401f9

Please sign in to comment.