gabrielgio.me @ 61d3d2541cf6b81ecb046b267a00cceaebc85b6f

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