macroblog.rs @ 77281bfab6d35556f121b95980dc6dccd0243842

 1Every time that I do a clean install on my machine it takes a few hours
 2till I get to point where I was before formatting it, install all
 3packages, select themes, icons, fonts, install IDEs, extensions and so
 4on. After doing it a few times I came to the conclusion that I would
 5save time by spending time automating this chore, and as a result, I
 6could tinker a little more with my system and not worry about spending a
 7weekend re-installing everything (which have happened more time that
 8        I\'d like to remember).
 9
10So after a few attempts using python and bash I ended with many files
11and keep everything organized and concise turned out to be more tedious
12than the setup itself. So there comes
13[Ansible](https://www.ansible.com/). It is an enterprise-graded software
14used to automate tasks. It has A LOT OF features and it can be really
15helpful if you\'re a sysadmin but for now we\'re going to focus on
16[Ansible
17Pull](https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html#ansible-pull)
18and
19[Playbooks](https://docs.ansible.com/ansible/latest/user_guide/playbooks.html).
20As better described:
21
22> \[Ansible-Pull\] is used to up a remote copy of ansible on each
23> managed node, each set to run via cron and update playbook source via
24> a source repository. This inverts the default push architecture of
25> Ansible into a pull architecture, which has near-limitless scaling
26> potential.
27>
28> Playbooks are Ansible's configuration, deployment, and orchestration
29> language. They can describe a policy you want your remote systems to
30> enforce, or a set of steps in a general IT process.
31>
32> [source](https://docs.ansible.com/ansible/latest/cli/ansible-pull.html)
33
34The goal is to pull and run a playbook remotely using a git repository.
35The playbook will describe the tasks needed to setup our machine from
36scratch.
37
38But first lets tinker a bit a with playbooks locally with
39`ansible-playbook`, to do so we need to add `localhost` to ansible\'s
40hosts list. Add it to `/etc/ansible/hosts`:
41
42``` service
43[all]
44localhost
45```
46
47As an experiment we\'re going to write a asks to install vim. Currently,
48   I\'m using [Fedora](https://getfedora.org/) thus we going to use [dnf
49   modeule](https://docs.ansible.com/ansible/latest/modules/dnf_module.html)
50   to install packages, but if you\'re using another distribution look for
51   a equivalent module like [apt
52   module](https://docs.ansible.com/ansible/latest/modules/apt_module.html)
53   for [Ubuntu](https://ubuntu.com/).
54
55   The playbook to install is quite simple:
56
57   ``` yaml
58# main.yaml
59   - hosts: all
60   tasks:
61   - name: install vim
62   dnf:
63name: vim
64state: latest
65```
66
67`hosts:` is required and it has to match our hosts otherwise the
68playbook won\'t run.
69
70`tasks:` is the list of tasks that the playbook will perform, in this
71case will be `dnf install vim`.
72
73To run a playbook use the command `ansible-playbook` commando to run
74`main.yml` direct from disk, do to so just run the following command:
75
76
77``` bash
78sudo ansible-playbook --connection=local main.yml
79```
80
81After a few seconds, vim will be installed on your machine.
82
83``` bash
84PLAY [all] *************************************************************
85
86TASK [Gathering Facts] *************************************************
87ok: [localhost]
88
89TASK [install vim] *****************************************************
90ok: [localhost]
91
92PLAY RECAP *************************************************************
93localhost                  : ok=2    changed=0    unreachable=0    failed=0
94```
95
96This is the first step, next part we shall create a more complex
97playbook and setup repository to run it remotely using `ansible-pull`.