qb 0.1.15 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ae9aeb0e2f878eadc6e1cf220a2a7e26783fd358
4
- data.tar.gz: c13dd57a5475abe283a69ca5b941b14df7cf7394
3
+ metadata.gz: 2c2374013aa43093a1e6faafe2a950b5afb5f91d
4
+ data.tar.gz: 4d205b08c8bd2a79dd3d4ab1b78e0eaeb38fdf28
5
5
  SHA512:
6
- metadata.gz: 94c65c40bee65ff720d9cb28ab0e119a4da69f62d831e0dbef002e0f9b77f4649d78ee97e85ca9e4d8f650e92075c81a80d3479d3db880185238fde38e18bdd2
7
- data.tar.gz: 851f4d7785b1b68310b7003393d2deb1a638345da45de47912c85651f931936a79013132f90c79307f435a65ecf89d50254c91fa7b3a4ecacb4fb73abc200998
6
+ metadata.gz: 92b37faef82d48f9c2220721c3e41ce1b90b54884b0cae9b790611f982cf0bee6064e7daf8d66031bb667eaea54e21310b789e770ed7bdaa0b35ee6813ee669e
7
+ data.tar.gz: 1d53cce2a2734001aecddd5d11b2db2d170b497431b4908eae46c75aeeee2e7f9214c65130cc4dadc1fa7d0474df11a335afd9519e4d9823a879c77892c55555
@@ -1,7 +1,7 @@
1
1
  module QB
2
2
  GEM_NAME = 'qb'
3
3
 
4
- VERSION = "0.1.15"
4
+ VERSION = "0.1.16"
5
5
 
6
6
  def self.gemspec
7
7
  Gem.loaded_specs[GEM_NAME]
@@ -168,16 +168,7 @@ def check_file_attrs(module, changed, message):
168
168
  message += "ownership, perms or SE linux context changed"
169
169
 
170
170
  return message, changed
171
-
172
-
173
- def startswith_lines(marker, lines, index):
174
- for i in range(0, len(marker)):
175
- if lines[i] == marker[0 + index]:
176
- pass
177
- else:
178
- return False
179
- return True
180
-
171
+
181
172
 
182
173
  def main():
183
174
  module = AnsibleModule(
@@ -194,7 +185,10 @@ def main():
194
185
  beginmarker=dict(default=None, type='str'),
195
186
  endmarker=dict(default=None, type='str'),
196
187
  ),
197
- mutually_exclusive=[['insertbefore', 'insertafter']],
188
+ mutually_exclusive=[
189
+ ['insertbefore', 'insertafter'],
190
+ ['block', 'src'],
191
+ ],
198
192
  add_file_common_args=True,
199
193
  supports_check_mode=True
200
194
  )
@@ -213,16 +207,22 @@ def main():
213
207
  module.fail_json(rc=257,
214
208
  msg='Destination %s does not exist !' % dest)
215
209
  original = ''
216
- lines = []
217
210
  else:
218
211
  f = open(dest, 'rb')
219
212
  original = f.read()
220
213
  f.close()
221
- lines = original.splitlines()
222
214
 
223
215
  insertbefore = params['insertbefore']
224
216
  insertafter = params['insertafter']
225
- block = params['block']
217
+
218
+ # accept `src` as a file for the block contents
219
+ if params['src']:
220
+ srcFile = open(params['src'], 'rb')
221
+ block = srcFile.read()
222
+ srcFile.close()
223
+ else:
224
+ block = params['block']
225
+
226
226
  marker = params['marker']
227
227
  present = params['state'] == 'present'
228
228
 
@@ -253,7 +253,6 @@ def main():
253
253
  marker0 = re.sub('', marker0, '')
254
254
  marker1 = re.sub('', marker1, '')
255
255
  else:
256
- # blocklines = []
257
256
  pass
258
257
 
259
258
  # make sure each chunk ends with a newline if it doens't already
@@ -271,7 +270,7 @@ def main():
271
270
  # module.fail_json(msg=pprint.pformat(replacement))
272
271
 
273
272
  exact_re = re.compile(
274
- (re.escape(marker0) + re.escape(block) + re.escape(marker1)),
273
+ re.escape(marker0 + block + marker1),
275
274
  (re.MULTILINE | re.DOTALL)
276
275
  )
277
276
 
@@ -303,10 +302,10 @@ def main():
303
302
  # 4. insert - the markers
304
303
  else:
305
304
  lines = original.splitlines()
306
- blocklines = replacement.splitlines()
307
305
 
308
306
  n0 = None
309
307
  if insertre is not None:
308
+ match = insertre.search(original)
310
309
  for i, line in enumerate(lines):
311
310
  if insertre.search(line):
312
311
  n0 = i
@@ -319,13 +318,18 @@ def main():
319
318
  else:
320
319
  n0 = len(lines) # insertafter=EOF
321
320
 
322
- lines[n0:n0] = blocklines
323
-
324
- if lines:
325
- result = '\n'.join(lines)+'\n'
326
- else:
327
- result = ''
321
+ before = "\n".join(lines[:n0])
322
+
323
+ if before != '':
324
+ before = before + "\n"
325
+
326
+ after = "\n".join(lines[n0:])
327
+
328
+ if after != '' and original.endswith("\n"):
329
+ after = after + "\n"
328
330
 
331
+ result = "".join([before, replacement, after])
332
+
329
333
  if original == result:
330
334
  msg = ''
331
335
  changed = False
@@ -10,7 +10,12 @@ var_prefix: null
10
10
  # how to get a default for `dir` if it's not provided as the
11
11
  default_dir: null
12
12
 
13
- vars:
13
+ vars:
14
+ - name: force
15
+ type: boolean
16
+ description: force operations (overwrite)
17
+ short: f
18
+
14
19
  - name: role_name
15
20
  type: string
16
21
  description: name of the role.
@@ -24,7 +29,7 @@ vars:
24
29
  - name: files
25
30
  type: boolean
26
31
  description: create a files directory.
27
- short: f
32
+ short: i
28
33
 
29
34
  - name: handlers
30
35
  type: boolean
@@ -13,7 +13,7 @@
13
13
  template:
14
14
  src: defaults/main.yml.j2
15
15
  dest: "{{ dir }}/defaults/main.yml"
16
- force: false
16
+ force: "{{ role_force }}"
17
17
  when: role_defaults
18
18
 
19
19
  # files
@@ -31,7 +31,7 @@
31
31
  copy:
32
32
  content: ""
33
33
  dest: "{{ dir }}/files/.gitkeep"
34
- force: false
34
+ force: "{{ role_force }}"
35
35
  when: role_files
36
36
 
37
37
  # handlers
@@ -47,7 +47,7 @@
47
47
  template:
48
48
  src: handlers/main.yml.j2
49
49
  dest: "{{ dir }}/handlers/main.yml"
50
- force: false
50
+ force: "{{ role_force }}"
51
51
  when: role_handlers
52
52
 
53
53
  # meta
@@ -63,7 +63,7 @@
63
63
  template:
64
64
  src: meta/main.yml.j2
65
65
  dest: "{{ dir }}/meta/main.yml"
66
- force: false
66
+ force: "{{ role_force }}"
67
67
  when: role_meta
68
68
 
69
69
  # tasks
@@ -79,7 +79,7 @@
79
79
  template:
80
80
  src: tasks/main.yml.j2
81
81
  dest: "{{ dir }}/tasks/main.yml"
82
- force: false
82
+ force: "{{ role_force }}"
83
83
  when: role_tasks
84
84
 
85
85
  # templates
@@ -97,7 +97,7 @@
97
97
  copy:
98
98
  content: ""
99
99
  dest: "{{ dir }}/templates/.gitkeep"
100
- force: false
100
+ force: "{{ role_force }}"
101
101
  when: role_templates
102
102
 
103
103
  # vars
@@ -113,5 +113,5 @@
113
113
  template:
114
114
  src: vars/main.yml.j2
115
115
  dest: "{{ dir }}/vars/main.yml"
116
- force: false
116
+ force: "{{ role_force }}"
117
117
  when: role_vars
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-05 00:00:00.000000000 Z
11
+ date: 2016-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler