Question

I'm new to configuration management tool. I want to use Ansible.

I'd like to set proxy to several GNU/Linux Debian (in fact several Raspbian).

I'd like to append

export http_proxy=http://cache.domain.com:3128

to /home/pi/.bashrc

I also want to append

Acquire::http::Proxy "http://cache.domain.com:3128";

to /etc/apt.conf

I want to set DNS to IP X1.X2.X3.X4 creating a /etc/resol.conf file with

nameserver X1.X2.X3.X4

What playbook file should I write ? How should I apply this playbook to my servers ?

Was it helpful?

Solution 2

I second jpmens. This is a very basic problem in Ansible, and a very good way to get started using the docs, tutorials and example playbooks.

However, if you're stuck or in a hurry, you can solve this like this (everything takes place on the "ansible master") :

Create a roles structure like this :

cd your_playbooks_directory
mkdir -p roles/pi/{templates,tasks,vars}

Now create roles/pi/tasks/main.yml :

- name: Adds resolv.conf
  template: src=resolv.conf.j2 dest=/etc/resolv.conf mode=0644

- name: Adds proxy env setting to pi user
  lineinfile: dest=~pi/.bashrc regexp="^export http_proxy" insertafter=EOF line="export http_proxy={{ http_proxy }}"

Then roles/pi/templates/resolv.conf.j2 :

nameserver {{ dns_server }}

then roles/pi/vars/main.yml :

dns_server: 8.8.8.8
http_proxy: http://cache.domain.com:3128

Now make a top-level playbook to apply roles, at your playbook root, and call it site.yml :

- hosts : raspberries
  roles:
    - { role: pi }

You can apply your playbook using :

ansible-playbook site.yml

assuming your machines are in the raspberries group.

Good luck.

OTHER TIPS

Start by learning a bit about Ansible basics and familiarize yourself with playbooks. Basically you ensure you can SSH in to your Raspian machines (using keys) and that the user Ansible invokes on these machines can run sudo. (That's the hard bit.)

The easy bit is creating the playbook for the tasks at hand, and there are plenty of pointers to example playbooks in the documentation.

If you really want to add a line to a file or two, use the lineinfile module, although I strongly recommend you create templates for the files you want to push to your machines and use those with the template module. (lineinfile can get quite messy.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top