diff options
| author | boom2 <blizzack@blizzack.com> | 2023-11-21 14:11:56 -0500 |
|---|---|---|
| committer | boom2 <blizzack@blizzack.com> | 2023-11-21 14:11:56 -0500 |
| commit | 62766cf1fd721d278e95821e05e6b41f7888eed5 (patch) | |
| tree | 35c0866b9dbc09cdc695435a3aa6aa1424cac1a4 /ansible-practice | |
initial commit
Diffstat (limited to 'ansible-practice')
| -rw-r--r-- | ansible-practice/01-playbook-hello.yml | 11 | ||||
| -rw-r--r-- | ansible-practice/02-playbook-list-files.yml | 15 | ||||
| -rw-r--r-- | ansible-practice/03-playbook-local-action.yml | 13 | ||||
| -rw-r--r-- | ansible-practice/04-playbook-create-file.yml | 14 | ||||
| -rw-r--r-- | ansible-practice/05-playbook-add-content-to-created-file.yml | 16 | ||||
| -rw-r--r-- | ansible-practice/06-playbook-create-multiple-files.yml | 19 | ||||
| -rw-r--r-- | ansible-practice/07-playbook-create-directory.yml | 14 | ||||
| -rw-r--r-- | ansible-practice/08-playbook-remove-directory.yml | 14 | ||||
| -rw-r--r-- | ansible-practice/09-playbook-remove-files-with-wildcard.yml | 21 | ||||
| -rw-r--r-- | ansible-practice/10-playbook-shutdown.yml | 17 | ||||
| -rw-r--r-- | ansible-practice/11-playbook-reboot.yml | 23 | ||||
| -rw-r--r-- | ansible-practice/12-playbook-copy-directory.yml | 19 | ||||
| -rw-r--r-- | ansible-practice/12-playbook-copy-directory.yml~ | 14 |
13 files changed, 210 insertions, 0 deletions
diff --git a/ansible-practice/01-playbook-hello.yml b/ansible-practice/01-playbook-hello.yml new file mode 100644 index 0000000..d668dea --- /dev/null +++ b/ansible-practice/01-playbook-hello.yml @@ -0,0 +1,11 @@ +# hello world +# https://www.digitalocean.com/community/tutorial-series/how-to-write-ansible-playbooks +--- + +- name: "01 - Playing with Ansible - hello world" + hosts: all + tasks: + - name: Print message + debug: + msg: Hello Ansible World +...
\ No newline at end of file diff --git a/ansible-practice/02-playbook-list-files.yml b/ansible-practice/02-playbook-list-files.yml new file mode 100644 index 0000000..1056387 --- /dev/null +++ b/ansible-practice/02-playbook-list-files.yml @@ -0,0 +1,15 @@ +# list files on a host +# https://www.middlewareinventory.com/blog/run-ansible-playbook-locally/ + +--- +- name: "02 - Playing with Ansible - list files on a system" + hosts: all +# hosts: localhost +# connection: local + tasks: + - name: "just execute a ls -lrt command" + shell: "ls -lrt" + register: "output" + + - debug: var=output.stdout_lines +...
\ No newline at end of file diff --git a/ansible-practice/03-playbook-local-action.yml b/ansible-practice/03-playbook-local-action.yml new file mode 100644 index 0000000..787a6c3 --- /dev/null +++ b/ansible-practice/03-playbook-local-action.yml @@ -0,0 +1,13 @@ +# how to use the 'local_action' module to list files locally +# this is not working !!! +# https://www.middlewareinventory.com/blog/run-ansible-playbook-locally/ + +--- +- name: "03 - Playing with Ansible - using local_action module" + tasks: + - name: "just execute a ls -lrt command" + local_action: shell ls -lrt + register: "output" + + - debug: var=output.stdout_lines +...
\ No newline at end of file diff --git a/ansible-practice/04-playbook-create-file.yml b/ansible-practice/04-playbook-create-file.yml new file mode 100644 index 0000000..f12d33b --- /dev/null +++ b/ansible-practice/04-playbook-create-file.yml @@ -0,0 +1,14 @@ +# creating a file +# https://phoenixnap.com/kb/ansible-create-file + +--- +- name: "04 - Playing with Ansible - creating a file" + hosts: all +# hosts: localhost +# connection: local + tasks: + - name: Creating an empty file + file: + path: "~/ansible_created_file-01.txt" + state: touch +...
\ No newline at end of file diff --git a/ansible-practice/05-playbook-add-content-to-created-file.yml b/ansible-practice/05-playbook-add-content-to-created-file.yml new file mode 100644 index 0000000..de3fdb6 --- /dev/null +++ b/ansible-practice/05-playbook-add-content-to-created-file.yml @@ -0,0 +1,16 @@ +# creating a file w/ content +# https://phoenixnap.com/kb/ansible-create-file + +--- +- name: "05 - Playing with Ansible - creating a file w/ content" +# hosts: all + hosts: localhost + connection: local + tasks: + - name: Creating a file with content + copy: + dest: "~/ansible_created_file-02.txt" + content: | + line 01 + line 02 +...
\ No newline at end of file diff --git a/ansible-practice/06-playbook-create-multiple-files.yml b/ansible-practice/06-playbook-create-multiple-files.yml new file mode 100644 index 0000000..3a6284b --- /dev/null +++ b/ansible-practice/06-playbook-create-multiple-files.yml @@ -0,0 +1,19 @@ +# create multiple empty files +# https://phoenixnap.com/kb/ansible-create-file + +--- +- name: "06 - Playing with Ansible - create multiple empty files" + hosts: all +# hosts: localhost +# connection: local + tasks: + - name: Create multiple files + file: + path: "~/{{ item }}" + state: touch + with_items: + - ansible_created_file-03.txt + - ansible_created_file-04.txt + - ansible_created_file-05.txt + - ansible_created_file-06.txt +...
\ No newline at end of file diff --git a/ansible-practice/07-playbook-create-directory.yml b/ansible-practice/07-playbook-create-directory.yml new file mode 100644 index 0000000..ba4affc --- /dev/null +++ b/ansible-practice/07-playbook-create-directory.yml @@ -0,0 +1,14 @@ +# create a directory +# https://phoenixnap.com/kb/ansible-create-file + +--- +- name: "07 - Playing with Ansible - create a directory" +# hosts: all + hosts: localhost + connection: local + tasks: + - name: Create a new directory + file: + path: "~/ansible_created_directory" + state: directory +...
\ No newline at end of file diff --git a/ansible-practice/08-playbook-remove-directory.yml b/ansible-practice/08-playbook-remove-directory.yml new file mode 100644 index 0000000..638cb19 --- /dev/null +++ b/ansible-practice/08-playbook-remove-directory.yml @@ -0,0 +1,14 @@ +# remove a directory (or file) +# https://phoenixnap.com/kb/ansible-create-file + +--- +- name: "08 - Playing with Ansible - remove a directory (or file)" +# hosts: all + hosts: localhost + connection: local + tasks: + - name: Remove a directory (or file) + file: + path: "~/ansible_created_directory" + state: absent +...
\ No newline at end of file diff --git a/ansible-practice/09-playbook-remove-files-with-wildcard.yml b/ansible-practice/09-playbook-remove-files-with-wildcard.yml new file mode 100644 index 0000000..046d18d --- /dev/null +++ b/ansible-practice/09-playbook-remove-files-with-wildcard.yml @@ -0,0 +1,21 @@ +# remove multiple files using globbing +# https://phoenixnap.com/kb/ansible-create-file +# https://www.freekb.net/Article?id=573 + +--- +- name: "09 - Playing with Ansible - remove a multiple files with globbing" +# hosts: all + hosts: localhost + connection: local + tasks: + - name: Find files with a pattern + find: + paths: "~/" + patterns: "ansible_created_file*" + register: result + - name: Remove multiple files with pattern above + file: + path: "{{ item.path }}" + state: absent + with_items: "{{ result.files }}" +... diff --git a/ansible-practice/10-playbook-shutdown.yml b/ansible-practice/10-playbook-shutdown.yml new file mode 100644 index 0000000..198bc90 --- /dev/null +++ b/ansible-practice/10-playbook-shutdown.yml @@ -0,0 +1,17 @@ +# shutdown a host +# https://docs.ansible.com/ansible/latest/collections/community/general/shutdown_module.html +# +# had to run the command like so: +# +# ansible-playbook 10-playboot-shutdown.yml --ask-become-pass + +--- +- name: "10 - Playing with Ansible - shutdown a host" + hosts: all + tasks: + - name: shutdown a host + community.general.shutdown: + msg: "shutdown initiated by ansible" + delay: 5 + become: yes +...
\ No newline at end of file diff --git a/ansible-practice/11-playbook-reboot.yml b/ansible-practice/11-playbook-reboot.yml new file mode 100644 index 0000000..3790a8e --- /dev/null +++ b/ansible-practice/11-playbook-reboot.yml @@ -0,0 +1,23 @@ +# reboot a host +# https://www.freekb.net/Article?id=3078 +# https://www.freekb.net/Article?id=2395 +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/reboot_module.html +# +# - will need to find another option for reboot cuz this was a wonky behavior from ansible +# - it asked me to enter my passphrase 5 times before actually took properly +# +# had to run the command like so: +# +# ansible-playbook 11-playboot-reboot.yml --ask-become-pass + +--- +- name: "11 - Playing with Ansible - reboot a host" + hosts: all + tasks: + - name: reboot a host + ansible.builtin.reboot: + msg: "reboot initiated by ansible" + connect_timeout: 5 + post_reboot_delay: 30 + become: yes +...
\ No newline at end of file diff --git a/ansible-practice/12-playbook-copy-directory.yml b/ansible-practice/12-playbook-copy-directory.yml new file mode 100644 index 0000000..00a5fd8 --- /dev/null +++ b/ansible-practice/12-playbook-copy-directory.yml @@ -0,0 +1,19 @@ +# copy directories from control node to managed node +# https://www.freekb.net/Article?id=759 +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html +# + +--- +- name: "12 - Playing with Ansible - copy directories from control to managed node" + hosts: all + tasks: + - name: copy entire directory + ansible.builtin.copy: + src: /home/dpierre/ansible-practice + dest: /home/dpierre/tmp/temp_files + + - name: copy directory contents + ansible.builtin.copy: + src: /home/dpierre/tmp/grubstuff/ + dest: /home/dpierre/tmp/temp_files/grub_files/ +...
\ No newline at end of file diff --git a/ansible-practice/12-playbook-copy-directory.yml~ b/ansible-practice/12-playbook-copy-directory.yml~ new file mode 100644 index 0000000..1d68918 --- /dev/null +++ b/ansible-practice/12-playbook-copy-directory.yml~ @@ -0,0 +1,14 @@ +# copy a directory from control node to managed node +# https://www.freekb.net/Article?id=759 +# https://docs.ansible.com/ansible/latest/collections/ansible/builtin/copy_module.html +# + +--- +- name: "12 - Playing with Ansible - copy a directory from contol to managed node" + hosts: all + tasks: + - name: copy a directory from contol to managed node + ansible.builtin.copy: + src: /home/dpierre/ansible-practice/ + dest: /home/dpierre/tmp/temp_files/ansible-practice +...
\ No newline at end of file |
