Ansible: Unterschied zwischen den Versionen
Aus Alexander's Wiki
Admin (Diskussion | Beiträge) |
Admin (Diskussion | Beiträge) K (→playbook.yml) |
||
(15 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt) | |||
Zeile 1: | Zeile 1: | ||
= Installation (Control machine) = | = Ansible Terms = | ||
* Controller Machine: the machine where Ansible is installed, responsible for running the provisioning on the servers you are managing | |||
* Inventory: an INI file that contains information about the servers you are managing | |||
* Playbook: the entry point for Ansible provisionings, where the automation is defined through tasks using YAML format | |||
* Task: a block that defines a single procedure to be executed, e.g.: install a package | |||
* Module: a module typically abstracts a system task, like dealing with packages or creating and changing files. Ansible has a multitude of built-in modules, but you can also create custom ones | |||
* Role: a pre-defined way for organizing playbooks and other files in order to facilitate sharing and reusing portions of a provisioning | |||
* Play: a provisioning executed from start to finish is called a play | |||
* Facts: global variables containing information about the system, like network interfaces or operating system | |||
* Handlers: used to trigger service status changes, like restarting or stopping a service | |||
Ansible provisionings are written using YAML, a simple data serialization language. | |||
= Installation (Ubuntu) = | |||
<source lang="bash" encl="div"> | |||
apt-get install software-properties-common | |||
apt-add-repository ppa:ansible/ansible | |||
apt-get update | |||
apt-get install ansible | |||
</source> | |||
= Installation (Manuell, Control machine) = | |||
<source lang="bash" encl="div"> | <source lang="bash" encl="div"> | ||
git clone git://github.com/ansible/ansible.git --recursive | git clone git://github.com/ansible/ansible.git --recursive | ||
Zeile 6: | Zeile 27: | ||
source ./hacking/env-setup | source ./hacking/env-setup | ||
apt-get install build-essential libssl-dev libffi-dev python-dev | |||
apt-get install python-setuptools | apt-get install python-setuptools | ||
easy_install pip | |||
pip install paramiko PyYAML Jinja2 httplib2 six | pip install paramiko PyYAML Jinja2 httplib2 six | ||
</source> | |||
= Update (Manuell) = | |||
Beim Update von Ansible müssen auch die Submodule mit upgedated werden. Diese geschieht durch die beiden Befehle: | |||
<source lang="bash" encl="div"> | |||
git pull --rebase | |||
git submodule update --init --recursive | |||
</source> | |||
= Benutzung = | |||
== hosts == | |||
hinzufügen: | |||
<source lang="bash" encl="div"> | |||
[servers] | |||
10.200.5.117 | |||
</source> | |||
== group_vars == | |||
Damit ansible nicht den verwendeten Nutzer zum Anmelden am Remote verwendet: | |||
* mkdir /etc/ansible/group_vars | |||
* nano /etc/ansible/group_vars/servers | |||
<source lang="bash" encl="div"> | |||
--- | |||
ansible_connection: ssh | |||
ansible_ssh_user: root | |||
ansible_ssh_pass: vagrant | |||
</source> | |||
== Test 1 == | |||
<source lang="bash" encl="div"> | |||
ansible -m ping servers | |||
</source> | |||
== Shell == | |||
<source lang="bash" encl="div"> | |||
ansible -m shell -a 'free -m' host1 | |||
</source> | |||
== playbook.yml == | |||
ansible-playbook playbook.yml --ask-sudo-pass | |||
<source lang="bash" encl="div"> | |||
- hosts: all | |||
become: true | |||
vars: | |||
packages: [ 'hsm-base', 'hsm-sqlanywhere', 'hsm-sqlanywhere-config' ] | |||
tasks: | |||
- name: Install apt-https support | |||
apt: name=apt-transport-https state=latest | |||
- name: Set package repository | |||
shell: echo "deb [arch=amd64] http://10.200.5.115:9000/hsm-2.0.1-54/ HAGLEITNER_SM main" > /etc/apt/sources.list.d/byansible.list | |||
- name: Install pgp key | |||
shell: wget -O - https://*****:*****@hsmupdate.hagleitner.com/hsm-arm-ring0/conf/Linova.gpg.key | apt-key add - | |||
- name: Update apt | |||
apt: update_cache=yes | |||
- name: Install Package | |||
apt: name={{ item }} state=latest | |||
with_items: packages | |||
</source> | </source> |
Aktuelle Version vom 17. Oktober 2016, 13:34 Uhr
Ansible Terms
* Controller Machine: the machine where Ansible is installed, responsible for running the provisioning on the servers you are managing * Inventory: an INI file that contains information about the servers you are managing * Playbook: the entry point for Ansible provisionings, where the automation is defined through tasks using YAML format * Task: a block that defines a single procedure to be executed, e.g.: install a package * Module: a module typically abstracts a system task, like dealing with packages or creating and changing files. Ansible has a multitude of built-in modules, but you can also create custom ones * Role: a pre-defined way for organizing playbooks and other files in order to facilitate sharing and reusing portions of a provisioning * Play: a provisioning executed from start to finish is called a play * Facts: global variables containing information about the system, like network interfaces or operating system * Handlers: used to trigger service status changes, like restarting or stopping a service
Ansible provisionings are written using YAML, a simple data serialization language.
Installation (Ubuntu)
apt-get install software-properties-common
apt-add-repository ppa:ansible/ansible
apt-get update
apt-get install ansible
Installation (Manuell, Control machine)
git clone git://github.com/ansible/ansible.git --recursive
cd ./ansible
source ./hacking/env-setup
apt-get install build-essential libssl-dev libffi-dev python-dev
apt-get install python-setuptools
easy_install pip
pip install paramiko PyYAML Jinja2 httplib2 six
Update (Manuell)
Beim Update von Ansible müssen auch die Submodule mit upgedated werden. Diese geschieht durch die beiden Befehle:
git pull --rebase
git submodule update --init --recursive
Benutzung
hosts
hinzufügen:
[servers]
10.200.5.117
group_vars
Damit ansible nicht den verwendeten Nutzer zum Anmelden am Remote verwendet:
- mkdir /etc/ansible/group_vars
- nano /etc/ansible/group_vars/servers
---
ansible_connection: ssh
ansible_ssh_user: root
ansible_ssh_pass: vagrant
Test 1
ansible -m ping servers
Shell
ansible -m shell -a 'free -m' host1
playbook.yml
ansible-playbook playbook.yml --ask-sudo-pass
- hosts: all
become: true
vars:
packages: [ 'hsm-base', 'hsm-sqlanywhere', 'hsm-sqlanywhere-config' ]
tasks:
- name: Install apt-https support
apt: name=apt-transport-https state=latest
- name: Set package repository
shell: echo "deb [arch=amd64] http://10.200.5.115:9000/hsm-2.0.1-54/ HAGLEITNER_SM main" > /etc/apt/sources.list.d/byansible.list
- name: Install pgp key
shell: wget -O - https://*****:*****@hsmupdate.hagleitner.com/hsm-arm-ring0/conf/Linova.gpg.key | apt-key add -
- name: Update apt
apt: update_cache=yes
- name: Install Package
apt: name={{ item }} state=latest
with_items: packages