---
- name: Create FW rule
hosts: all
gather_facts: no
roles:
- role: robertdebock.mysql
become: yes
vars:
mysql_user_name: tony
tasks:
- include-tasks: tasks/useful.yml
- firewalld:
var: ansible_facts`
port: "{{ http_port | default('88') }}/tcp"
service: http
source: 192.0.0.0/24
zone: public
state: enabled
permanent: yes #(persist reboot)
immediate: yes #(enable now)
- name: Generate password
shell: pwgen -N 1 -s 30
register: myPass
- name: Print the generated password
debug:
msg: "The password is {{ myPass }}";
port line above, you must use double quote " around the variable.- hosts: server1
tasks:
- name: Install git and restart nginx
block:
- name: install Git
yum: name=git state=present
- name: Restart nginx
service: name=nginx state=restarted
become: yes
when: ansible_facts['distribution']=='CentOS'
rescue: # Do this if the task fail
- mail:
to: admin@domain.com
subject: Houston, We've Got a Problem
body: task {{ ansible_failed_task.name }}
always: # Always do this
- mail:
to: user@domain.com
subject: "{{ ansible_play_name }} status"
body: "{{ ansible_failed_result }}"
|
hostvars['srv1'].ip_address
|
Get vars value defined for another host
|
|
hostvars['srv1'].ansible_facts.mounts
|
Get facts value from another host
|
|
hostvars['srv1'][ansible_facts][mounts]
|
Same as above writen diffrently
|
|
group_names
|
Get all groups the current host is part of
|
|
inventory_hostname
|
Get the current host name define in inventory not the FQDN
|
|
gather_facts: False
|
Disable facts gathering
|
|
forks=50 (in ansible.cfg)
|
or --forks 50 or -f 50 on CLI (default is 5)
|
|
[ssh_connection] (in ansible.cfg)
ssh_args = -o ControlMaster=auto -o ControlPersist=60s |
|
|
pipelining = True (in ansible.cfg)
|
Reduce the number of SSH connections
|
|
strategy: free
|
Execute tasks without waiting for other hosts to finish their tasks
|
all:
hosts:
mail.example.com:
ansible_host: 192.168.1.230
ansible_user: mailmin
children:
webservers:
hosts:
frcllweb001:
ansible_host: 192.168.1.231
|
1. $ANSIBLE_CONFIG
|
|
2. ansible.cfg in playbook dir
|
|
3. ~/.ansible.cfg
|
|
4. /etc/ansible/ansible.cfg
|
|
any_errors_fatal: true
|
Will stop & exit playbook if any error
|
|
ignore_errors: true
|
Execute next tasks on failed hosts
|
|
failed_when: <condition>
|
Task fail when condition is met
|
#!/usr/bin/ansibleNo comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.