macroblog.rs @ b4472b41214eeeacce071df41bf0f782e1f16d6d

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