gabrielgio.me @ beccd4b2a4730325b18f52aae6f457b2c593dc85

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