-
Notifications
You must be signed in to change notification settings - Fork 0
/
bashps.yml
82 lines (73 loc) · 1.79 KB
/
bashps.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
- hosts: all
gather_facts: false
vars_files:
- vars/bashps/{{ env }}.yml
tasks:
- name: get current hostname
shell: hostname
register: cur_hostname
tags: hostname
- name: convert hostname to lowercase
hostname:
name: "{{ cur_hostname.stdout | lower }}"
when: cur_hostname.stdout.islower() == False
tags: hostname
# - include: tasks/check_hostname.yml
- name: find all bashrc
shell: find /home -type f -name .bashrc
register: result
tags: ps
- name: remove PS1 from all bashrc I
replace:
backup: yes
dest: "{{ item }}"
regexp: \# this block is managed by Ansible\nPS1=.*\n.*m.*\n.*31m.*\n# block end
replace: ''
with_items:
- "{{ result.stdout_lines }}"
- /root/.bashrc
- /etc/skel/.bashrc
- /etc/bashrc
tags: ps
when: env is defined
- name: remove PS1 from all bashrc II
replace:
backup: yes
dest: "{{ item }}"
regexp: PS1=.*\n.*m.*\n.*31m.*
replace: ''
with_items:
- "{{ result.stdout_lines }}"
- /root/.bashrc
- /etc/skel/.bashrc
- /etc/bashrc
tags: ps
when: env is defined
- name: replace PS1
blockinfile:
backup: yes
block: "{{ bashps }}"
dest: "{{ item }}"
state: present
insertafter: .*PS1=.*
insertafter: PS1=.*\n.*m.*\n.*31m.*
with_items:
- "{{ result.stdout_lines }}"
- /root/.bashrc
- /etc/skel/.bashrc
- /etc/bashrc
tags: ps
when: env is defined
# - name: append ps1 to bashrc
# lineinfile: |
# dest="{{ item }}"
# line="{{ bashps }}"
# insertafter=EOF
# with_items:
# - "{{ result.stdout_lines }}"
# - /root/.bashrc
# - /etc/bashrc
# - /etc/skel/.bashrc
# when: env is defined
# tags: ps