commit be982083f457034ee4312f6c6ea7867cc1332468 Author: Dimitrije Date: Tue Aug 22 15:48:17 2023 +0200 first commit 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