gabrielgio.me @ 2dacc92f01056d24a0af49f007079a79825ff048

  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 like)
 16
 17So after a few attempts using python and bash, I couldn't get something 
 18that scales and ended with many files and keep the files organized and
 19concise turned 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
 37So what we're gonna do is pull a playbook from a git account a run on
 38the host, that playbook will have the tasks that we need to setup our
 39machine.
 40
 41To run it locally first we need localhost to all hosts list, to do so we
 42only the following text 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 tasks:
 60     - name: install vim
 61       dnf:
 62         name: vim
 63         state: latest
 64{% endhighlight %}
 65
 66Fist `hosts:` it is required and it has to match our hosts so we are
 67able to run that playbook. Then `tasks:` which is a list of task that
 68the playbook will perform that in this case will be `dnf install` for
 69the package vim.
 70
 71Ansible pull requires a repository but for the first example I want to
 72keep it simple so we will use `ansible-playbook` commando to run
 73`main.yml` direct from disk, do to so just run the following command:
 74
 75{% highlight bash %}
 76sudo ansible-playbook --connection=local main.yml
 77{% endhighlight %}
 78
 79After a few seconds, vim will be installed on your machine.
 80{% highlight bash %}
 81PLAY [all] *************************************************************
 82
 83TASK [Gathering Facts] *************************************************
 84ok: [localhost]
 85
 86TASK [install vim] *****************************************************
 87ok: [localhost]
 88
 89PLAY RECAP *************************************************************
 90localhost                  : ok=2    changed=0    unreachable=0    failed=0  
 91{% endhighlight %}
 92 
 93This is the first step, next part we shall create a more complex
 94playbook and setup repo and actually use `ansible-pull`
 95
 96
 97
 98 
 99
100