gabrielgio.me @ f05cb3e05d34e3454f2b47862343f0a09cf69da0

  1---
  2layout: post
  3title:  "Automating desktop setup with ansible-pull part-1"
  4date:   2019-03-07
  5tags: ['ansible', 'ansible-pull', 'linux', 'fedora']
  6---
  7
  8Every time that I do a clean install on my machine it takes a few hours
  9till I get to point where I was before formatting it, install all
 10packages, select themes, icons, fonts, install IDEs, extensions and so
 11on. After doing it a few times I came to the conclusion (
 12[genius](https://i.imgur.com/BtWuQgT.png)) that It would be nice to
 13automate this chore, and as a result, I could tinker a little more with
 14my system and not be afraid of spending a weekend reinstalling
 15everything (which have happened more time that I'd likei to remenber)
 16
 17So after a few attempts using python or/and bash, I couldn't get something 
 18that scales and ended with many files and keep the files organized and
 19concise turned out to be more tedious than the setup itself. So it comes
 20[Ansible](https://www.ansible.com/). It is an enterprise-grade software
 21used to automate tasks. It has many features I can be really helpful as
 22a sysadmin but what we gonna focus here is cliente side of thing using
 23[Ansible Pull](https://docs.ansible.com/ansible/latest/user_guide/playbooks_intro.html#ansible-pull)
 24and
 25[Playbooks](https://docs.ansible.com/ansible/latest/user_guide/playbooks.html)
 26as better describe:
 27
 28> Ansible-Pull is used to up a remote copy of ansible on each managed 
 29> node, each set to run via cron and update playbook source via a source
 30> repository. This inverts the default push architecture of ansible into
 31> a pull architecture, which has near-limitless scaling potential.
 32
 33> Playbooks are Ansible’s configuration, deployment, and orchestration 
 34> language. They can describe a policy you want your remote systems to
 35> enforce, or a set of steps in a general IT process.
 36
 37The next step is to pull a playbook from a git account and run on
 38the host, the playbook will have tasks needed to setup our
 39machine.
 40
 41To run it locally first we need to add localhost to hosts list, to do so we
 42only the following text added to `/etc/ansible/hosts`:
 43
 44{% highlight text %} 
 45[all] 
 46localhost 
 47{% endhighlight %}
 48
 49As an experiment we're gonna make tasks to install vim. Currently, I
 50using
 51[Fedora](https://getfedora.org/) thus we going to use
 52[dnf modeule](https://docs.ansible.com/ansible/latest/modules/dnf_module.html)
 53to install packages
 54
 55The playbook to install is quite simple:
 56
 57{% highlight yml %}
 58# main.yml
 59- hosts: all 
 60  tasks:
 61     - name: install vim
 62       dnf:
 63         name: vim
 64         state: latest
 65{% endhighlight %}
 66
 67Fist `hosts:` it is required and it has to match our hosts so we are
 68able to run that playbook. Then `tasks:` which is a list of task that
 69the playbook will perform that in this case will be `dnf install` for
 70the vim package.
 71
 72Ansible pull requires a repository but for the first example I want to
 73keep it simple so we will use `ansible-playbook` commando to run
 74`main.yml` direct from disk, do to so just run the following command:
 75
 76{% highlight bash %}
 77sudo ansible-playbook --connection=local main.yml
 78{% endhighlight %}
 79
 80After a few seconds, vim will be installed on your machine.
 81{% highlight bash %}
 82PLAY [all] *************************************************************
 83
 84TASK [Gathering Facts] *************************************************
 85ok: [localhost]
 86
 87TASK [install vim] *****************************************************
 88ok: [localhost]
 89
 90PLAY RECAP *************************************************************
 91localhost                  : ok=2    changed=0    unreachable=0    failed=0  
 92{% endhighlight %}
 93 
 94This is the first step, next part we shall create a more complex
 95playbook and setup repo and actually use `ansible-pull`
 96
 97
 98
 99 
100
101