Add a simple command to dump Ansible configuration for one or more hosts
This commit is contained in:
parent
cbd6fcc522
commit
f066dd286c
@ -1,22 +1,37 @@
|
||||
---
|
||||
- hosts: all
|
||||
gather_facts: "{{ gather_facts | default(False) }}"
|
||||
# Variables:
|
||||
# - dump_path: Path to directory to store variable dumps (optional)
|
||||
# - dump_facts: Whether to include gathered facts in the dump (optional)
|
||||
# - dump_hosts: Group/host specifier for hosts to dump (optional)
|
||||
# - dump_var_name: Name of the option to dump (optional)
|
||||
|
||||
- name: Dump configuration from one or more hosts
|
||||
hosts: "{{ dump_hosts | default('all') }}"
|
||||
gather_facts: "{{ dump_facts | default(False) }}"
|
||||
vars:
|
||||
dump_config_path: /tmp/kayobe-dump-config
|
||||
dump_path: /tmp/kayobe-dump-config
|
||||
tasks:
|
||||
- name: Create configuration dump directory
|
||||
file:
|
||||
path: "{{ dump_config_path }}"
|
||||
path: "{{ dump_path }}"
|
||||
state: directory
|
||||
|
||||
- name: Write host config to file
|
||||
local_action:
|
||||
module: copy
|
||||
content: "{{ hostvars[inventory_hostname] | to_nice_yaml }}"
|
||||
dest: "{{ dump_config_path }}/{{ inventory_hostname }}.yml"
|
||||
dest: "{{ dump_path }}/{{ inventory_hostname }}.yml"
|
||||
when: "{{ dump_var_name is not defined }}"
|
||||
|
||||
- name: Write merged config to file
|
||||
- name: Write host variable to file
|
||||
local_action:
|
||||
module: copy
|
||||
content: "{{ hostvars | merge_config | to_nice_yaml }}"
|
||||
dest: "{{ dump_config_path }}/merged.yml
|
||||
content: "{{ hostvars[inventory_hostname][dump_var_name] | to_nice_yaml }}"
|
||||
dest: "{{ dump_path }}/{{ inventory_hostname }}.yml"
|
||||
when: "{{ dump_var_name is defined }}"
|
||||
|
||||
# - name: Write merged config to file
|
||||
# local_action:
|
||||
# module: copy
|
||||
# content: "{{ hostvars | merge_config | to_nice_yaml }}"
|
||||
# dest: "{{ dump_path }}/merged.yml
|
||||
|
18
kayobe-config-dump
Executable file
18
kayobe-config-dump
Executable file
@ -0,0 +1,18 @@
|
||||
#!/bin/bash
|
||||
|
||||
dump_dir=$(mktemp -d)
|
||||
|
||||
# Execute the dump-config.yml playbook.
|
||||
./kayobe-playbook \
|
||||
ansible/dump-config.yml \
|
||||
-e dump_path=${dump_dir} \
|
||||
$@ \
|
||||
> /dev/null
|
||||
|
||||
result=$?
|
||||
|
||||
if [[ $result -eq 0 ]]; then
|
||||
cat ${dump_dir}/*.yml
|
||||
fi
|
||||
rm -rf ${dump_dir}
|
||||
exit $result
|
Loading…
Reference in New Issue
Block a user