1<section>
2 <a href="/posts/2019-03-07Automating_desktop_setup_with_ansible-pull_part-1.html">See part 1</a>
3 <p>
4 Now we're going to setup ansible to work with a git repository. The process is
5 quite similar to ansible-playbook, the only difference is that the source for
6 the playbook will be a remote repository and not a local file. Following the
7 previous example we'll get vim setup automated.
8 </p>
9 <p>
10 Create a git repository wherever you see
11 fit, <a href="https://about.gitlab.com/">gitlab</a>
12 and <a href="https://github.com/">github</a> offer free repositories. For
13 this task we need to add only two file: one for the yml file describing the
14 tasks and the .vimrc file.
15 </p>
16 <p>
17 In the .vimrc add your own configuration, you can see
18 mine
19 <a href="https://gitlab.com/gabrielgio/homestation/-/blob/debcf3458df511aef9f7dca0cb73f6cf6baddd5d/.vimrc">
20 over here
21 </a>, it is pretty simple as I don't use it but for simple text editing
22 (like this post) so you can start with that if you don't have one.
23 </p>
24 <p>
25 The yml file will have two tasks, one is to install vim, just like we did in the part 1.
26<pre><code># main.yml
27---
28- name: install vim
29 dnf:
30 name: vim
31 state: latest</code></pre>
32 </p>
33 <p>
34 To copy .vimrc file to your $HOME we going to
35 use <a href="https://docs.ansible.com/ansible/latest/modules/copy_module.html">copy
36 module</a>:
37 </p>
38 <p>
39 After we've added those two files to repository you will have be something
40 <a href="https://gitlab.com/gabrielgio/homestation/-/tree/debcf3458df511aef9f7dca0cb73f6cf6baddd5d">
41 like this.
42 </a>
43 <br/>
44 Parms:
45 <ul>
46 <li><strong>-i</strong> is a list of hosts</li>
47 <li><strong>-U</strong> is the get repository url</li>
48 </ul>
49 </p>
50 <p>
51 Remember man is your best friend, take a look at <code>man ansible-pull</code> to know
52 more about its parameters.
53 </p>
54 <p>
55 The best part you can quickly test and see the result by running my sample:
56<pre><code>ansible-pull \
57 -U https://gitlab.com/gabrielgio/homestation.git \
58 -C debcf3458df511aef9f7dca0cb73f6cf6baddd5d \
59 -i all \
60 main.yml</code></pre>
61 </p>
62 <p>
63 The idea here is to keep your repository as a source of truth when comes to
64 configuration, you can add ansible-pull to a CRON tab, so you just need to
65 push something to your repository and after a few minutes not only your
66 machine but all the machines that have it setup will run the playbooks. You
67 can use this method as a simple way to install software, update machines or
68 even distribute tooling company-wise.
69 </p>
70</section>