kayobe/ansible/dump-config.yml
Mark Goddard d8fe45b3d8 Tag all (well, some of) the things (plays)
Having tagged plays allows us to easily run a subset of the plays for a
command, and perform targeted operations with less risk of unintended
consequences.

The tags are typically named after the playbook, although some of the
overcloud playbooks have been tagged without an overcloud- prefix.
2017-12-19 16:58:21 +00:00

43 lines
1.3 KiB
YAML

---
# 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 }}"
gather_facts: "{{ dump_facts }}"
tags:
- dump-config
vars:
dump_path: /tmp/kayobe-dump-config
dump_facts: no
dump_hosts: all
tasks:
- name: Create configuration dump directory
local_action:
module: file
path: "{{ dump_path }}"
state: directory
- name: Write host config to file
local_action:
module: copy
content: "{{ hostvars[inventory_hostname] | to_nice_yaml }}"
dest: "{{ dump_path }}/{{ inventory_hostname }}.yml"
when: dump_var_name is not defined
- name: Write host variable to file
local_action:
module: copy
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