Skip to content
Snippets Groups Projects
Commit c4f46c4f authored by Rafael László's avatar Rafael László :speech_balloon:
Browse files

Merge branch 'dev-arcter' into 'master'

Add example playbook

See merge request !1
parents daa3ec06 7a1a4709
No related branches found
No related tags found
1 merge request!1Add example playbook
This is an example playbook.
Kubernetes example: https://git.sch.bme.hu/kszk/sysadmin/kubernetes/cluster-setup/-/tree/master/ansible/mgmt
- 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 }}"
You may place your files here that should be copyed to the target machine,
and doesn't need templating.
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
---
- 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
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
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
```
list:
- one: 1
- two: 2
- three: 3
user: {name: user1 , home_address: moon}
\ No newline at end of file
all:
#You should be able to SSH into all of these machines
hosts:
# Use OpenSSH config to make it comfortable
host1.sch.bme.hu:
......
You place here your usual playbook.
Example: https://git.sch.bme.hu/kszk/sysadmin/kubernetes/cluster-setup/-/tree/master/ansible/mgmt
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment