From d8a7729358a2fd3b911022e45d0197fda3e5da94 Mon Sep 17 00:00:00 2001 From: boom2 Date: Fri, 8 Dec 2023 14:12:33 -0500 Subject: - add exeriments for: - roles - variables - inventory changes - config changes --- .../system/06-playbook-print-group-vars.yml | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 ansible-practice/system/06-playbook-print-group-vars.yml (limited to 'ansible-practice/system/06-playbook-print-group-vars.yml') diff --git a/ansible-practice/system/06-playbook-print-group-vars.yml b/ansible-practice/system/06-playbook-print-group-vars.yml new file mode 100644 index 0000000..850bea2 --- /dev/null +++ b/ansible-practice/system/06-playbook-print-group-vars.yml @@ -0,0 +1,44 @@ + +# https://stackoverflow.com/questions/53253879/ansible-vars-files-vs-include-vars +# https://docs.ansible.com/ansible/2.7/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable + +# https://www.middlewareinventory.com/blog/run-ansible-playbook-locally/ +# https://nixzie.com/run-ansible-playbook-locally/#Run_Ansible_Playbook_Locally_Using_Local_Action +# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_delegation.html#delegating-facts +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debug_module.html +# https://docs.ansible.com/ansible-core/2.15/reference_appendices/interpreter_discovery.html + +--- +- name: "06" + hosts: localhost +# hosts: "*" + tasks: + - name: Print the gateway for each host when defined + ansible.builtin.debug: + msg: System {{ inventory_hostname }} has gateway {{ ansible_default_ipv4.gateway }} + when: ansible_default_ipv4.gateway is defined + + - name: Print the ansible python interpreter + ansible.builtin.debug: + msg: + - "ansible_playbook_python = {{ ansible_playbook_python }}" +# - "ansible_python_interpreter = {{ ansible_python_interpreter }}" + + - name: Print the ansible python interpreter - for the localhost + ansible.builtin.debug: + msg: + - "ansible_playbook_python = {{ ansible_playbook_python }}" + - "ansible_host = {{ ansible_host }}" +# - "ansible_python_interpreter = {{ ansible_python_interpreter }}" + delegate_to: localhost + run_once: true + + - name: Print the ansible python interpreter - using 'local_action' + local_action: + module: ansible.builtin.debug + var: ansible_playbook_python + run_once: true + + - name: Print the group variable + ansible.builtin.debug: + msg: prefix variable = {{ prefix_dir }} -- cgit v1.2.3-54-g00ecf