Distribution de travail : Ubuntu 17.10 Serveur de test : Machine virtuelle Gandi
Ouvrir :
/etc/hosts
Chercher :
127.0.0.1 localhost
Ajouter après :
217.70.191.12 serv01
util06@station06:~$ ssh-keygen
util06@station06:~$ sudo ssh-copy-id admin@serv01
util06@station06:~$ ssh admin@serv01
util06@station06:~$ sudo apt-get install software-properties-common
util06@station06:~$ sudo apt-add-repository ppa:ansible/ansible
util06@station06:~$ sudo apt-get update
util06@station06:~$ sudo apt-get install ansible
Créer :
/etc/ansible/hosts
Ajouter :
[web]
217.70.191.12 ansible_user=admin
util06@station06:~$ ansible -m ping all --one-line
217.70.191.12 | SUCCESS => {"changed": false, "ping": "pong"}
util06@station06:~$ ansible all -m command --args "uptime" --one-line
217.70.191.12 | CHANGED | rc=0 | (stdout) 15:23:47 up 1:51, 1 user, load average: 0.08, 0.02, 0.01
util06@station06:~$ ansible web -m command -u genma --args "df -h" --one-line
217.70.191.12 | CHANGED | rc=0 | (stdout) Filesystem Size Used Avail Use% Mounted on\nudev 234M 0 234M 0% /dev\ntmpfs 49M 1.9M 47M 4% /run\n/dev/xvda1 9.8G 760M 8.6G 8% /\ntmpfs 244M 0 244M 0% /dev/shm\ntmpfs 5.0M 0 5.0M 0% /run/lock\ntmpfs 244M 0 244M 0% /sys/fs/cgroup\ntmpfs 24K 0 24K 0% /var/gandi
util06@station06:~$ mkdir -p ANSIBLE/playbook
util06@station06:~$ cd ANSIBLE/playbook
util06@station06:~/ANSIBLE/playbook$
Créer :
/home/util06/ANSIBLE/playbook/updateupgrade.yml
Ajouter :
- hosts: web
become: yes
become_user: root
become_method: su
tasks:
- name: update and upgrade apt packages
apt:
update_cache=yes
state=latest
upgrade=yes
util06@station06:~/ANSIBLE/playbook$ ansible-playbook -i /etc/ansible/hosts updateupgrade.yml -K
SUDO password:
PLAY [web] *********************************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************
ok: [217.70.191.12]
TASK [update and upgrade apt packages] *****************************************************************************************************
[WARNING]: Could not find aptitude. Using apt-get instead.
changed: [217.70.191.12]
PLAY RECAP *********************************************************************************************************************************
217.70.191.12 : ok=2 changed=1 unreachable=0 failed=0
util06@station06:~/ANSIBLE/playbook$
Créer :
/home/util06/ANSIBLE/playbook/package_base.yml
Ajouter :
- hosts: web
become: yes
become_user: root
become_method: su
tasks:
- name: install common base packages for all servers
apt:
update_cache=yes
state=latest
name={{item}}
with_items:
- htop
- vim
- screen
- mc
util06@station06:~/ANSIBLE/playbook$ ansible-playbook -i /etc/ansible/hosts package_base.yml -K
SUDO password:
PLAY [web] *********************************************************************************************************************************
TASK [Gathering Facts] *********************************************************************************************************************
ok: [217.70.191.12]
TASK [install common base packages for all servers] ****************************************************************************************
changed: [217.70.191.12] => (item=[u'htop', u'vim', u'screen', u'mc'])
PLAY RECAP *********************************************************************************************************************************
217.70.191.12 : ok=2 changed=1 unreachable=0 failed=0
util06@station06:~/ANSIBLE/playbook$
Créer :
locale.yml
Ajouter :
- hosts: web
become: yes
become_user: root
become_method: su
tasks:
- name: generate locales
locale_gen:
name: '{{ item }}'
state: present
with_items:
- fr_FR.UTF-8
- name: set default locale
lineinfile:
dest: /etc/default/locale
regexp: '^LANG=.*$'
line: 'LANG=fr_FR.UTF-8'
create: yes
state: present
- name: set timezone
file:
src: /usr/share/zoneinfo/Europe/Paris
dest: /etc/localtime
force: yes
state: link
Action :
ansible-playbook -i /etc/ansible/hosts locale.yml -K