mirror of https://github.com/ansible/ansible.git
Add state option to git_config module (#50578)
* Add state option to git_config module State present/absent option works like --set/--unset option for 'git config'. * Change git_config to avoid useless parameter passed to git command When unsetting value, command was : git config --unset foo ''. Now command is : git config --unset foo. * Add some integration tests to git_config module * Add missing aliases file * Change set up method Using git command seems to cause troubles on some OS : changing config by changing '.gitconfig' file. * Remove some distros from tests pool Git is not installed or is out of date on these distros. * Fix aliases to skip tests on centos6 * Refactor tests of the git_config module * Add use case when state=absent and value is definedpull/52061/head
parent
984777b3d0
commit
2f85d62989
@ -0,0 +1,2 @@
|
|||||||
|
shippable/posix/group3
|
||||||
|
|
@ -0,0 +1,2 @@
|
|||||||
|
[http]
|
||||||
|
proxy = foo
|
@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
- import_tasks: setup_no_value.yml
|
||||||
|
|
||||||
|
- name: testing exclusion between state and list_all parameters
|
||||||
|
git_config:
|
||||||
|
list_all: true
|
||||||
|
state: absent
|
||||||
|
register: result
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: assert git_config failed
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- result is failed
|
||||||
|
- "result.msg == 'parameters are mutually exclusive: list_all, state'"
|
||||||
|
...
|
@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
- import_tasks: setup_no_value.yml
|
||||||
|
|
||||||
|
- name: setting value without state
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
value: "{{ option_value }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
register: set_result
|
||||||
|
|
||||||
|
- name: getting value without state
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
register: get_result
|
||||||
|
|
||||||
|
- name: assert set changed and value is correct
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- set_result.changed == true
|
||||||
|
- set_result.diff.before == "\n"
|
||||||
|
- set_result.diff.after == option_value + "\n"
|
||||||
|
- get_result.changed == false
|
||||||
|
- get_result.config_value == option_value
|
||||||
|
...
|
@ -0,0 +1,27 @@
|
|||||||
|
---
|
||||||
|
- import_tasks: setup_no_value.yml
|
||||||
|
|
||||||
|
- name: setting value with state=present
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
value: "{{ option_value }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
state: present
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: getting value with state=present
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
state: present
|
||||||
|
register: get_result
|
||||||
|
|
||||||
|
- name: assert set changed and value is correct with state=present
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- set_result.changed == true
|
||||||
|
- set_result.diff.before == "\n"
|
||||||
|
- set_result.diff.after == option_value + "\n"
|
||||||
|
- get_result.changed == false
|
||||||
|
- get_result.config_value == option_value
|
||||||
|
...
|
@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
# test code for the git_config module
|
||||||
|
|
||||||
|
- name: setup
|
||||||
|
import_tasks: setup.yml
|
||||||
|
|
||||||
|
- block:
|
||||||
|
# testing parameters exclusion: state and list_all
|
||||||
|
- import_tasks: exclusion_state_list-all.yml
|
||||||
|
# testing get/set option without state
|
||||||
|
- import_tasks: get_set_no_state.yml
|
||||||
|
# testing get/set option with state=present
|
||||||
|
- import_tasks: get_set_state_present.yml
|
||||||
|
# testing state=absent without value to delete
|
||||||
|
- import_tasks: unset_no_value.yml
|
||||||
|
# testing state=absent with value to delete
|
||||||
|
- import_tasks: unset_value.yml
|
||||||
|
# testing state=absent with value to delete and a defined value parameter
|
||||||
|
- import_tasks: precedence_between_unset_and_value.yml
|
||||||
|
# testing state=absent with check mode
|
||||||
|
- import_tasks: unset_check_mode.yml
|
||||||
|
when: git_installed is succeeded and git_version.stdout is version(git_version_supporting_includes, ">=")
|
||||||
|
...
|
@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
- import_tasks: setup_value.yml
|
||||||
|
|
||||||
|
- name: unsetting value
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
state: absent
|
||||||
|
value: bar
|
||||||
|
register: unset_result
|
||||||
|
|
||||||
|
- name: getting value
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
register: get_result
|
||||||
|
|
||||||
|
- name: assert unset changed and deleted value
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- unset_result.changed == true
|
||||||
|
- unset_result.diff.before == option_value + "\n"
|
||||||
|
- unset_result.diff.after == "\n"
|
||||||
|
- get_result.config_value == ''
|
||||||
|
...
|
@ -0,0 +1,11 @@
|
|||||||
|
---
|
||||||
|
- name: verify that git is installed so this test can continue
|
||||||
|
command: which git
|
||||||
|
register: git_installed
|
||||||
|
ignore_errors: yes
|
||||||
|
|
||||||
|
- name: get git version, only newer than {{git_version_supporting_includes}} has includes option
|
||||||
|
shell: "git --version | grep 'git version' | sed 's/git version //'"
|
||||||
|
register: git_version
|
||||||
|
ignore_errors: yes
|
||||||
|
...
|
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
# ------
|
||||||
|
# set up : deleting gitconfig file
|
||||||
|
- name: set up without value
|
||||||
|
file:
|
||||||
|
path: ~/.gitconfig
|
||||||
|
state: absent
|
||||||
|
...
|
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
# ------
|
||||||
|
# set up : set gitconfig with value
|
||||||
|
- name: set up with value
|
||||||
|
copy:
|
||||||
|
src: gitconfig
|
||||||
|
dest: ~/.gitconfig
|
||||||
|
...
|
@ -0,0 +1,25 @@
|
|||||||
|
---
|
||||||
|
- import_tasks: setup_value.yml
|
||||||
|
|
||||||
|
- name: unsetting value with check mode
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
state: absent
|
||||||
|
check_mode: yes
|
||||||
|
register: unset_result
|
||||||
|
|
||||||
|
- name: getting value
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
register: get_result
|
||||||
|
|
||||||
|
- name: assert unset changed but dit not delete value
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- unset_result.changed == true
|
||||||
|
- unset_result.diff.before == option_value + "\n"
|
||||||
|
- unset_result.diff.after == "\n"
|
||||||
|
- get_result.config_value == option_value
|
||||||
|
...
|
@ -0,0 +1,23 @@
|
|||||||
|
---
|
||||||
|
- import_tasks: setup_no_value.yml
|
||||||
|
|
||||||
|
- name: unsetting value
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
state: absent
|
||||||
|
register: unset_result
|
||||||
|
|
||||||
|
- name: getting value
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
register: get_result
|
||||||
|
|
||||||
|
- name: assert unsetting didn't change
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- unset_result.changed == false
|
||||||
|
- unset_result.msg == 'no setting to unset'
|
||||||
|
- get_result.config_value == ''
|
||||||
|
...
|
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
- import_tasks: setup_value.yml
|
||||||
|
|
||||||
|
- name: unsetting value
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
state: absent
|
||||||
|
register: unset_result
|
||||||
|
|
||||||
|
- name: getting value
|
||||||
|
git_config:
|
||||||
|
name: "{{ option_name }}"
|
||||||
|
scope: "{{ option_scope }}"
|
||||||
|
register: get_result
|
||||||
|
|
||||||
|
- name: assert unset changed and deleted value
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- unset_result.changed == true
|
||||||
|
- unset_result.diff.before == option_value + "\n"
|
||||||
|
- unset_result.diff.after == "\n"
|
||||||
|
- get_result.config_value == ''
|
||||||
|
...
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
git_version_supporting_includes: 1.7.10
|
||||||
|
option_name: http.proxy
|
||||||
|
option_value: 'foo'
|
||||||
|
option_scope: global
|
||||||
|
...
|
Loading…
Reference in New Issue