macroblog.rs @ master

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