From be982083f457034ee4312f6c6ea7867cc1332468 Mon Sep 17 00:00:00 2001 From: Dimitrije Date: Tue, 22 Aug 2023 15:48:17 +0200 Subject: [PATCH] first commit --- README.md | 21 +++++++++++++++++++++ ansible.cfg | 6 ++++++ inventory/group_vars/all/vars.yml | 5 +++++ inventory/host_vars/mail.server.com | 0 inventory/host_vars/web.server.com.yml | 2 ++ inventory/inventory.yml | 2 ++ playbook.yml | 8 ++++++++ 7 files changed, 44 insertions(+) create mode 100644 README.md create mode 100644 ansible.cfg create mode 100644 inventory/group_vars/all/vars.yml create mode 100644 inventory/host_vars/mail.server.com create mode 100644 inventory/host_vars/web.server.com.yml create mode 100644 inventory/inventory.yml create mode 100644 playbook.yml diff --git a/README.md b/README.md new file mode 100644 index 0000000..b2afbe2 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# Taking small steps to learn Ansible; I will write as a notes to myself. + +## What is Ansible ? +Ansible is automation tool for making infrastructure as code. +Helps with managing multiple servers/machines from one code base, making sure all the servers where the ansible is executed have the same configuration. +Ansible is agentless, does not need installing ansible on target machine, only python interpreter. +### Nodes +- Control Node (From which is ansible executed to managed nodes) +- Managed Node (Server/Machine which we are managing such as remote hosts, PC-s, servers, embedded devices) + +## Ansible Repo (dir) +Consists of several parts: +- Inventory (Holds hosts to manage) +- Playbooks (What should be executed on the target host) +- Modules +- Ansible Configuration +### Playbooks +- Set of plays which are executed on target machine. +- Each play has a set of tasks +- Multiple repetetive tasks can be group inside **ROLES** +- **ROLES** (Tasks, Handlers, Vars, Plugins, Templates, Files) diff --git a/ansible.cfg b/ansible.cfg new file mode 100644 index 0000000..d988bbf --- /dev/null +++ b/ansible.cfg @@ -0,0 +1,6 @@ +# Ansible config file + + +[defaults] +any_fatal_errors=True +inventory = ./inventory diff --git a/inventory/group_vars/all/vars.yml b/inventory/group_vars/all/vars.yml new file mode 100644 index 0000000..5a1f38d --- /dev/null +++ b/inventory/group_vars/all/vars.yml @@ -0,0 +1,5 @@ +# This will load variables for ansible group all +# which is by ansible default all the hosts in inventory file +# This something like global variables which are accessible by all host +--- +ansible_user: root diff --git a/inventory/host_vars/mail.server.com b/inventory/host_vars/mail.server.com new file mode 100644 index 0000000..e69de29 diff --git a/inventory/host_vars/web.server.com.yml b/inventory/host_vars/web.server.com.yml new file mode 100644 index 0000000..e284f63 --- /dev/null +++ b/inventory/host_vars/web.server.com.yml @@ -0,0 +1,2 @@ +--- +ansible_host: 136.244.87.93 diff --git a/inventory/inventory.yml b/inventory/inventory.yml new file mode 100644 index 0000000..c7a5819 --- /dev/null +++ b/inventory/inventory.yml @@ -0,0 +1,2 @@ +web.server.com +mail.server.com diff --git a/playbook.yml b/playbook.yml new file mode 100644 index 0000000..0ac7bbd --- /dev/null +++ b/playbook.yml @@ -0,0 +1,8 @@ +- name: Name of play -> my first play + hosts: freebsd_machines + tasks: + - name: Ping my host + ansible.builtin.ping: + - name: Print message + ansible.builtin.debug: + msg: Hello world from freebsd