Skip to content

Instantly share code, notes, and snippets.

@nshenry03
Created October 11, 2018 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nshenry03/dd05ff99cfd33af22c7f94b70901dbd0 to your computer and use it in GitHub Desktop.
Save nshenry03/dd05ff99cfd33af22c7f94b70901dbd0 to your computer and use it in GitHub Desktop.
---
- hosts: all
gather_facts: no
vars:
user_list:
- name: john.doe
git_config:
- user.name: John Doe
- user.email: john.doe@example.com
- user.signingkey: 0A46826A
- name: jane.doe
git_config:
- user.name: Jane Doe
- diff.tool: meld
tasks:
- debug:
msg: "User: {{ item.0.name }}, Key: {{ item.1 }}"
loop: "{{ user_list | subelements('git_config') }}"
# Eventually, I would like to be able to do something like this using Ansible's git_config module: https://docs.ansible.com/ansible/2.4/git_config_module.html
# - git_config:
# name: "{{ item.1.key }}"
# value: "{{ item.1.value }}"
# scope: global
# loop: "{{ user_list | <<Some Ansible Magic>> }}"
# become: yes
# become_user: "{{ item.0.name }}"
@nshenry03
Copy link
Author

nshenry03 commented Oct 11, 2018

nhenry@nhenry-desktop:~/.local/tmp$ ansible-playbook git_config.yml 

PLAY [all] *********************************************************************************************************************************************************************************************************************************************************************************

TASK [debug] *******************************************************************************************************************************************************************************************************************************************************************************
ok: [localhost] => (item=[{u'name': u'john.doe', u'git_config': [{u'user.name': u'John Doe'}, {u'user.email': u'john.doe@example.com'}, {u'user.signingkey': u'0A46826A'}]}, {u'user.name': u'John Doe'}]) => {
    "msg": "User: john.doe, Key: {u'user.name': u'John Doe'}"
}
ok: [localhost] => (item=[{u'name': u'john.doe', u'git_config': [{u'user.name': u'John Doe'}, {u'user.email': u'john.doe@example.com'}, {u'user.signingkey': u'0A46826A'}]}, {u'user.email': u'john.doe@example.com'}]) => {
    "msg": "User: john.doe, Key: {u'user.email': u'john.doe@example.com'}"
}
ok: [localhost] => (item=[{u'name': u'john.doe', u'git_config': [{u'user.name': u'John Doe'}, {u'user.email': u'john.doe@example.com'}, {u'user.signingkey': u'0A46826A'}]}, {u'user.signingkey': u'0A46826A'}]) => {
    "msg": "User: john.doe, Key: {u'user.signingkey': u'0A46826A'}"
}
ok: [localhost] => (item=[{u'name': u'jane.doe', u'git_config': [{u'user.name': u'Jane Doe'}, {u'diff.tool': u'meld'}]}, {u'user.name': u'Jane Doe'}]) => {
    "msg": "User: jane.doe, Key: {u'user.name': u'Jane Doe'}"
}
ok: [localhost] => (item=[{u'name': u'jane.doe', u'git_config': [{u'user.name': u'Jane Doe'}, {u'diff.tool': u'meld'}]}, {u'diff.tool': u'meld'}]) => {
    "msg": "User: jane.doe, Key: {u'diff.tool': u'meld'}"
}

PLAY RECAP *********************************************************************************************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=0   

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment