Ansible

1
2
3
4
5
6
7
8
 ______________________________
< TASK [Enjoy using ansible :D] >
------------------------------
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||

Run ansible limited to some host

With --limit you can restrict on which hosts will be executed playbook.

1
ansible-playbook ovh.yml --limit front02 --tags nginx --skip-tags apt

Also with --tags and --skip-tags parameter you can choose which tags will be applied or not.

Restart server and wait

1
2
3
4
5
6
7
8
9
10
11
- name: reboot the server
shell: sleep 2 && shutdown -r now
async: 1
poll: 0
- name: Wait for server come back
wait_for: >
host={{ inventory_hostname }}
port=22
delay=15
timeout=600
delegate_to: localhost

Inventories

Tools

Simple playbooks

Load all sql files to mysql, one database for each one

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---

# ansible-playbook -K playbook.yml

- name: Load all database dumps
hosts: 127.0.0.1
connection: local
become: yes
tasks:

- name: Recursively find sql dump files
find:
paths: ./
patterns: '*.sql'
recurse: yes
register: "dumps"

- name: Listing files to be imported
debug:
msg: "Detected the next file {{ item.path }}"
with_items: "{{ dumps.files }}"

- name: Create a database for each file
mysql_db:
name: "recover_{{ item.path | replace('.', '_') | truncate(50, False, '') }}"
state: import
login_host: 127.0.0.1
login_user: root
login_password: hola
target: "{{ item.path }}"
with_items: "{{ dumps.files }}"

Comments

⬆︎TOP