gabrielgio.me @ ffef59e04b636518b06e2e5755caf9116c838620

 1---
 2layout: post
 3title:  "Automating desktop setup with ansible-pull part-2"
 4date:   2019-03-07
 5tags: ['ansible', 'ansible-pull', 'linux', 'fedora']
 6---
 7
 8[See part 1]({% post_url 2019-03-07-ansible-part-1 %})
 9
10Now we're gonna setup ansible to work with a git repository. The process is quite similar with `ansible-playbook` the only difference is that command will get a repository instead of a folder. Following the previews example we'll get vim setup automated.
11
12Do create a git repository wherever you see fit ([gitlab](https://about.gitlab.com/) and [github](https://github.com/) offer free repositories). For this task we're gonna need to add only two file: one for the `yml` file describing the task and the `.vimrc` file.
13
14In the `.vimrc` add your own configuration, you can see mine [over here](https://github.com/gabrielgio/homestation/blob/241b27285d8cba8548277f3508e097439831a6eb/config/.vimrc), it is pretty simple as I don't use it but for simple text editing (like this post) so you can start with it if you don't have one.
15
16The `yml` file will have two tasks, one is to install vim itself, it identical as it in the part 1.
17
18{% highlight yml %}
19# main.yml
20---
21- name: install vim
22  dnf:
23    name: vim
24    state: latest
25{% endhighlight %}
26
27Then we add the task to copy `.vimrc` file to your `$HOME`, for it we shall use [copy module](https://docs.ansible.com/ansible/latest/modules/copy_module.html):
28
29{% highlight yml %}
30---
31- name: copy vimrc file
32  copy:
33    src: config/.vimrc
34    dest: ~/
35    mode: 0644
36{% endhighlight %}
37
38After adding those two files your repository will be something [like this](https://github.com/gabrielgio/homestation/tree/debcf3458df511aef9f7dca0cb73f6cf6baddd5d).
39
40And now we just need to run `ansible-pull` command
41
42{% highlight bash %}
43ansible-pull -U <YOUR_REPO> -i all main.yml #you may need run it as a sudo
44{% endhighlight %} 
45
46The `-i` option it is a list of hosts. Remember `man` is your best friend take a look at `man ansible-pull` to know more about the params.
47
48The best part if you want to test quickly you can just run my sample and see the result:
49{% highlight bash %}
50ansible-pull -U https://github.com/gabrielgio/homestation.git -C debcf3458df511aef9f7dca0cb73f6cf6baddd5d -i all main.yml
51{% endhighlight %}
52
53The idea here is to keep your repository as a source of truth when comes to configuration, you can add this task to your cron tab,thus you just push something to your repository and after a few minutes no only your machine but all machine that have it setup will receive an update, you can use it as a simple way to install software, update machines or even distribute tools company-wise.