diff --git a/ansible/example-playbook/README.md b/ansible/example-playbook/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4324f4b4c505320ce7ee6a10a4d2fdee0882a35d --- /dev/null +++ b/ansible/example-playbook/README.md @@ -0,0 +1,3 @@ +This is an example playbook. + +Kubernetes example: https://git.sch.bme.hu/kszk/sysadmin/kubernetes/cluster-setup/-/tree/master/ansible/mgmt diff --git a/ansible/example-playbook/exampleplay.yml b/ansible/example-playbook/exampleplay.yml new file mode 100644 index 0000000000000000000000000000000000000000..8a004add82941027cdab39bb5d6e8bc85d9e1432 --- /dev/null +++ b/ansible/example-playbook/exampleplay.yml @@ -0,0 +1,25 @@ +- name: task examples + hosts: host1.sch.bme.hu + vars_files: + - vars/example.yml + tasks: + - name: Simple task + script: "echo hello world!" + + - name: Import task file + import_tasks: tasks/installpackage.yml + + - name: Only do task when requirement meet + debug: + msg: "Random task was executed" + when: condition + + - name: use vars + debug: + msg: "{{ user }}" + + - name: use loop + debug: + msg: "{{ item }}" + loop: + "{{ list }}" diff --git a/ansible/example-playbook/files/README.md b/ansible/example-playbook/files/README.md new file mode 100644 index 0000000000000000000000000000000000000000..511e4d6d15de7f196595bd76793bd5adf27aa58b --- /dev/null +++ b/ansible/example-playbook/files/README.md @@ -0,0 +1,2 @@ +You may place your files here that should be copyed to the target machine, +and doesn't need templating. diff --git a/ansible/example-playbook/tasks/README.md b/ansible/example-playbook/tasks/README.md new file mode 100644 index 0000000000000000000000000000000000000000..1a98e6f5b8ae77f75ab5977ef797defb7a25f471 --- /dev/null +++ b/ansible/example-playbook/tasks/README.md @@ -0,0 +1,5 @@ +You may place your task files here. + +Task files are a list of tasks that can be executed separetly. +You would use this if you want to group some tasks. +Ie: you want to install Podman on Ubuntu 20.04 diff --git a/ansible/example-playbook/tasks/installpackage.yml b/ansible/example-playbook/tasks/installpackage.yml new file mode 100644 index 0000000000000000000000000000000000000000..bdbeb01de6ef28308023d0a8332088f9479ac426 --- /dev/null +++ b/ansible/example-playbook/tasks/installpackage.yml @@ -0,0 +1,23 @@ +--- +- name: Add the GPG key for the repository + become: true + ansible.builtin.apt_key: + url: https://urlforgpgkey + state: present + +- name: Add the repository + become: true + ansible.builtin.apt_repository: + repo: "deb http://hu.archive.ubuntu.com/ubuntu/ focal main restricted" #Example line + state: present + +- name: "Update apt packages" + become: true + apt: + upgrade: yes + update_cache: yes + +- name: Install the software + apt: + name: Name_of_SW + state: present \ No newline at end of file diff --git a/ansible/example-playbook/templates/README.md b/ansible/example-playbook/templates/README.md new file mode 100644 index 0000000000000000000000000000000000000000..64f8104d0ff1fd15317f506aaedcd088b4dccc0a --- /dev/null +++ b/ansible/example-playbook/templates/README.md @@ -0,0 +1,15 @@ +You may place templates here. Templates can use variables that will be replaced by the task later. +Example for a template: +``` +This file holds the {{ meaning_of_life }}. +``` +If you give value for the `meaning_of_life`, then you can copy it by this task: +``` +- name: Use template + vars: + meaning_of_life: 42 + template: + src: ../templates/README.md + dest: /the/full/path/of/destination +# You may set other parameters of the target file such as owner or permissins +``` \ No newline at end of file diff --git a/ansible/example-playbook/vars/README.md b/ansible/example-playbook/vars/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ff377573f63010dfdb018f22a4231cba7d4d2fe7 --- /dev/null +++ b/ansible/example-playbook/vars/README.md @@ -0,0 +1,14 @@ +You may place your var files here. +Var files can hold variables that can be used by tasks, rules and playes. +The vars should use the "key: value" form. +If you use variables that should be encrypted you can do so by ansible-vault +Encrypt it + +```bash +ansible-vault encrypt file_name +``` + +Decrypt it +```bash +ansible-vault decrypt file_name +``` diff --git a/ansible/example-playbook/vars/example.yml b/ansible/example-playbook/vars/example.yml new file mode 100644 index 0000000000000000000000000000000000000000..1f5673426400c85b5f1ff7abc4c9b5e4d36c16b8 --- /dev/null +++ b/ansible/example-playbook/vars/example.yml @@ -0,0 +1,5 @@ +list: + - one: 1 + - two: 2 + - three: 3 +user: {name: user1 , home_address: moon} \ No newline at end of file diff --git a/ansible/inventory.yaml b/ansible/inventory.yaml index f47cfbc1200e34ca8386df49f49c66c79724d48c..0c2bdd90a5fa1c549157576621ad0bcfb04d1785 100644 --- a/ansible/inventory.yaml +++ b/ansible/inventory.yaml @@ -1,4 +1,5 @@ all: + #You should be able to SSH into all of these machines hosts: # Use OpenSSH config to make it comfortable host1.sch.bme.hu: diff --git a/ansible/playbook-name/README.md b/ansible/playbook-name/README.md deleted file mode 100644 index 3ccf8cd8ad3791d2dc1ee2ade99517728b099af1..0000000000000000000000000000000000000000 --- a/ansible/playbook-name/README.md +++ /dev/null @@ -1,3 +0,0 @@ -You place here your usual playbook. - -Example: https://git.sch.bme.hu/kszk/sysadmin/kubernetes/cluster-setup/-/tree/master/ansible/mgmt