roles/user/tasks/main.yml

changeset 28
6f7483dfe742
parent 17
d0d9fdf1f9d3
child 29
9b3befb1c773
equal deleted inserted replaced
27:98981c22420a 28:6f7483dfe742
1 --- 1 ---
2
3 # Create/update my user, don't clobber my extra groups. 2 # Create/update my user, don't clobber my extra groups.
4 - name: User setup 3 - name: User setup
5 user: 4 user:
6 name: "{{user.name}}" 5 name: "{{user.name}}"
7 comment: "{{user.comment}}" 6 comment: "{{user.comment}}"
9 groups: sudo 8 groups: sudo
10 append: true 9 append: true
11 register: user 10 register: user
12 tags: user 11 tags: user
13 12
14 - name: ssh | Pubkey for user 13 - name: ssh : Pubkey for user
15 authorized_key: 14 authorized_key:
16 manage_dir: true 15 manage_dir: true
17 user: "{{user.name}}" 16 user: "{{user.name}}"
18 key: "{{item}}" 17 key: "{{item}}"
19 with_file: 18 with_file:
20 - public_keys/{{user.name}} 19 - public_keys/{{user.name}}
21 tags: user, ssh 20 tags: user, ssh
22 21
23 - name: ssh | Ensure known_hosts keys 22 - name: ssh : Ensure known_hosts keys
24 become: true 23 become: true
25 become_user: "{{user.name}}" 24 become_user: "{{user.name}}"
26 lineinfile: 25 lineinfile:
27 dest: "{{user.home}}/.ssh/known_hosts" 26 dest: "{{user.home}}/.ssh/known_hosts"
28 state: present 27 state: present
30 create: true 29 create: true
31 mode: 0600 30 mode: 0600
32 with_dict: "{{hostkeys}}" 31 with_dict: "{{hostkeys}}"
33 tags: user, ssh 32 tags: user, ssh
34 33
35 - name: ssh | Purge invalid known_hosts keys 34 - name: ssh : Purge invalid known_hosts keys
36 become: true 35 become: true
37 become_user: "{{user.name}}" 36 become_user: "{{user.name}}"
38 lineinfile: 37 lineinfile:
39 dest: "{{user.home}}/.ssh/known_hosts" 38 dest: "{{user.home}}/.ssh/known_hosts"
40 state: absent 39 state: absent
44 43
45 44
46 # I like to make my ~ my dotfiles working directory (some folks symlink 45 # I like to make my ~ my dotfiles working directory (some folks symlink
47 # everything) Here that means I clone, move hg, then checkout, clobbering any 46 # everything) Here that means I clone, move hg, then checkout, clobbering any
48 # conflicts with /etc/skel stuff. 47 # conflicts with /etc/skel stuff.
49 - name: Check for dotfiles checkout in homedir
50 stat: path={{user.home}}/.hg
51 register: dotfiles
52 tags: user, dotfiles
53
54 - name: Clone dotfiles 48 - name: Clone dotfiles
55 when: dotfiles.stat.exists == false
56 shell: > 49 shell: >
57 hg clone -U {{dotfiles_repository}} {{user.home}}/_dotfiles_ 50 hg clone -U {{dotfiles_repository}} {{user.home}}/_dotfiles_
58 && mv {{user.home}}/_dotfiles_/.hg {{user.home}} 51 && mv {{user.home}}/_dotfiles_/.hg {{user.home}}
59 && rmdir {{user.home}}/_dotfiles_ 52 && rmdir {{user.home}}/_dotfiles_
60 && chown -R {{user.name}}:{{user.group}} {{user.home}}/.hg 53 && chown -R {{user.name}}:{{user.group}} {{user.home}}/.hg
61 && sudo -u {{user.name}} hg -R {{user.home}} update -C 54 && sudo -u {{user.name}} hg -R {{user.home}} update -C
55 args:
56 create: "{{user.home}}/.hg"
62 tags: user, dotfiles 57 tags: user, dotfiles
63 58
64 59
65 # This is an existing script that clones/updates zgen, rbenv, and plenv. 60 # This is an existing script that clones/updates zgen, rbenv, and plenv.
66 # My dotfiles use each if the right directory exists. 61 # My dotfiles use each if the right directory exists.
67 - name: Run homedir-setup 62 - name: Run homedir-setup
68 become: true 63 become: true
69 become_user: "{{user.name}}" 64 become_user: "{{user.name}}"
70 shell: bin/homedir-setup chdir={{user.home}} 65 shell: bin/homedir-setup
66 args:
67 chdir: "{{user.home}}"
71 register: homedir_setup 68 register: homedir_setup
72 changed_when: homedir_setup.stdout | match("Updating|Cloning") 69 changed_when: homedir_setup.stdout | match("Updating|Cloning")
73 failed_when: homedir_setup.rc != 0 70 failed_when: homedir_setup.rc != 0
74 tags: user, install 71 tags: user, install
75

mercurial