feat: automatically commit and push new host inventory changes to Git
This commit is contained in:
@@ -155,4 +155,16 @@
|
|||||||
{{ hostvars[item]['inventory_hostname'] }} ansible_host={{ hostvars[item]['ansible_host'] }}
|
{{ hostvars[item]['inventory_hostname'] }} ansible_host={{ hostvars[item]['ansible_host'] }}
|
||||||
insertafter: "^\\[lxc\\]"
|
insertafter: "^\\[lxc\\]"
|
||||||
marker: "# {mark} ANSIBLE MANAGED BLOCK FOR HOST {{ hostvars[item]['inventory_hostname'] }}"
|
marker: "# {mark} ANSIBLE MANAGED BLOCK FOR HOST {{ hostvars[item]['inventory_hostname'] }}"
|
||||||
loop: "{{ groups['new'] }}"
|
loop: "{{ groups['new'] }}"
|
||||||
|
|
||||||
|
- name: Commit and Push Inventory Changes to Git
|
||||||
|
ansible.builtin.shell: |
|
||||||
|
git config --global user.email "ansible@homelab.local"
|
||||||
|
git config --global user.name "Ansible Automation"
|
||||||
|
git add inventory/hosts.ini
|
||||||
|
git commit -m "Ansible: Added host {{ hostvars[item]['inventory_hostname'] }} to inventory"
|
||||||
|
git push
|
||||||
|
args:
|
||||||
|
chdir: "{{ playbook_dir }}/../"
|
||||||
|
loop: "{{ groups['new'] }}"
|
||||||
|
ignore_errors: yes
|
||||||
Reference in New Issue
Block a user