summaryrefslogtreecommitdiff
path: root/ansible-practice/system
diff options
context:
space:
mode:
Diffstat (limited to 'ansible-practice/system')
-rw-r--r--ansible-practice/system/03-playbook-print-gateway.yml16
-rw-r--r--ansible-practice/system/04-playbook-bash-configs.yml12
-rw-r--r--ansible-practice/system/05-playbook-bash-configs.yml31
-rw-r--r--ansible-practice/system/06-playbook-print-group-vars.yml44
-rw-r--r--ansible-practice/system/07-playbook-bash-configs.yml11
-rw-r--r--ansible-practice/system/vars/localhost.yml3
-rw-r--r--ansible-practice/system/vars/otherhosts.yml3
7 files changed, 120 insertions, 0 deletions
diff --git a/ansible-practice/system/03-playbook-print-gateway.yml b/ansible-practice/system/03-playbook-print-gateway.yml
new file mode 100644
index 0000000..7fd2277
--- /dev/null
+++ b/ansible-practice/system/03-playbook-print-gateway.yml
@@ -0,0 +1,16 @@
+# display some per host info using 'magic variables'
+# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/debug_module.html
+# https://docs.ansible.com/ansible/latest/inventory/implicit_localhost.html
+# https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_delegation.html
+#
+
+---
+- name: "03 - display some per host info"
+ hosts: all
+# hosts: localhost
+# connection: local
+ 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 \ No newline at end of file
diff --git a/ansible-practice/system/04-playbook-bash-configs.yml b/ansible-practice/system/04-playbook-bash-configs.yml
new file mode 100644
index 0000000..99da687
--- /dev/null
+++ b/ansible-practice/system/04-playbook-bash-configs.yml
@@ -0,0 +1,12 @@
+# - makes use of 'roles'
+# - experimenting w/ including variable files
+# - this only works when we create a '/vars' directory w/ our variables in it
+
+---
+- hosts: all
+#- hosts: localhost
+# connection: local
+ vars_files:
+ - [ "vars/{{ inventory_hostname }}.yml", "vars/otherhosts.yml" ]
+ roles:
+ - bash_config_old
diff --git a/ansible-practice/system/05-playbook-bash-configs.yml b/ansible-practice/system/05-playbook-bash-configs.yml
new file mode 100644
index 0000000..3f56745
--- /dev/null
+++ b/ansible-practice/system/05-playbook-bash-configs.yml
@@ -0,0 +1,31 @@
+# - similar to '02-playbook-copy-bash-configs.yml' but uses 'vars_files'
+# to store the variable 'prefix_dir' inside files representing
+# the environment
+
+---
+- name: "05 - custom ansible - copy bash config files w/ content"
+ hosts: localhost
+ connection: local
+ vars_files:
+ - [ "vars/{{ inventory_hostname }}.yml", "vars/otherhosts.yml" ]
+ tasks:
+ - name: copy '.bash_aliases'
+ ansible.builtin.copy:
+ src: ~/repos/ansible_repo/ansible-practice/system/.bash_aliases
+ dest: "{{ prefix_dir }}.bash_aliases"
+ mode: '0644'
+ tags: ['bash_aliases']
+
+ - name: Creating '.bashrc' file with content
+ ansible.builtin.copy:
+ src: ~/repos/ansible_repo/ansible-practice/system/.bashrc
+ dest: "{{ prefix_dir }}.bashrc"
+ mode: '0644'
+ tags: ['bashrc']
+
+ - name: Creating '.bash_profile' file with content
+ ansible.builtin.copy:
+ src: ~/repos/ansible_repo/ansible-practice/system/.bash_profile
+ dest: "{{ prefix_dir }}.bash_profile"
+ mode: '0644'
+ tags: ['bash_profile']
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 }}
diff --git a/ansible-practice/system/07-playbook-bash-configs.yml b/ansible-practice/system/07-playbook-bash-configs.yml
new file mode 100644
index 0000000..be77bc7
--- /dev/null
+++ b/ansible-practice/system/07-playbook-bash-configs.yml
@@ -0,0 +1,11 @@
+# - similar to '04-playbook-copy-bash-configs.yml'
+# - uses new changes in '~/.ansible/hosts'
+# - uses new additions inside the following files to store 'prefix_dir':
+# - '/home/dpierre/.ansible/group_vars/all'
+# - '/home/dpierre/.ansible/host_vars/localhost'
+
+---
+- name: "07 - custom ansible - copy bash config files w/ content"
+ hosts: localhost
+ roles:
+ - bash_config \ No newline at end of file
diff --git a/ansible-practice/system/vars/localhost.yml b/ansible-practice/system/vars/localhost.yml
new file mode 100644
index 0000000..c5727b6
--- /dev/null
+++ b/ansible-practice/system/vars/localhost.yml
@@ -0,0 +1,3 @@
+---
+# vars for localhost
+prefix_dir: ~/tmp/temp_files/
diff --git a/ansible-practice/system/vars/otherhosts.yml b/ansible-practice/system/vars/otherhosts.yml
new file mode 100644
index 0000000..1fe8201
--- /dev/null
+++ b/ansible-practice/system/vars/otherhosts.yml
@@ -0,0 +1,3 @@
+---
+# vars for other hosts
+prefix_dir: ~/