Skip to content

Instantly share code, notes, and snippets.

@naingyeminn
Last active December 12, 2018 12:18
Show Gist options
  • Save naingyeminn/65e5c39d109bd910d13c0a69aa184e58 to your computer and use it in GitHub Desktop.
Save naingyeminn/65e5c39d109bd910d13c0a69aa184e58 to your computer and use it in GitHub Desktop.
Ansible Lab
---
- name: play - one
hosts: vm01.example.com
tasks:
- name: write content
copy:
content: "{{ ansible_nodename }}"
dest: /tmp/managed_host.txt
- name: get content
command: cat /tmp/managed_host.txt
register: results
- debug:
msg: "content of managed_host.txt on {{ ansible_host }} is {{ results.stdout }}"
- name: write content with delegate_to
copy:
content: "{{ ansible_nodename }}"
dest: /tmp/managed_host.txt
delegate_to: vm02.example.com
- name: get content with delegate_to
command: cat /tmp/managed_host.txt
register: results
delegate_to: vm02.example.com
- debug:
msg: "content of managed_host.txt on {{ ansible_host }} is {{ results.stdout }}"
delegate_to: vm02.example.com
PLAY [play - one] ****************************************************************************
TASK [Gathering Facts] ***********************************************************************
ok: [vm01.example.com]
TASK [task - one] ****************************************************************************
ok: [vm01.example.com] => {
"msg": "Facts variable is from vm01.example.com and myvar is variable one"
}
PLAY RECAP ***********************************************************************************
vm01.example.com : ok=2 changed=0 unreachable=0 failed=0
---
- name: play - one
hosts: vm01.example.com
vars:
- myvar: variable one
tasks:
- name: task - one
debug:
msg: Facts variable is from {{ ansible_nodename }} and myvar is {{ myvar }}
PLAY [play - one] ****************************************************************************
TASK [Gathering Facts] ***********************************************************************
ok: [vm01.example.com]
TASK [task - one] ****************************************************************************
ok: [vm01.example.com] => {
"msg": "Facts variable is from vm01.example.com and myvar is variable one"
}
PLAY [play - two] ****************************************************************************
TASK [Gathering Facts] ***********************************************************************
ok: [vm02.example.com]
TASK [task - one] ****************************************************************************
ok: [vm02.example.com] => {
"msg": "Facts variable is from vm02.example.com and myvar is variable two"
}
PLAY RECAP ***********************************************************************************
vm01.example.com : ok=2 changed=0 unreachable=0 failed=0
vm02.example.com : ok=2 changed=0 unreachable=0 failed=0
---
- name: play - one
hosts: vm01.example.com
vars:
- myvar: variable one
tasks:
- name: task - one
debug:
msg: Facts variable is from {{ ansible_nodename }} and myvar is {{ myvar }}
- name: play - two
hosts: vm02.example.com
vars:
- myvar: variable two
tasks:
- name: task - one
debug:
msg: Facts variable is from {{ ansible_nodename }} and myvar is {{ myvar }}
PLAY [play - one] **********************************************************************************
TASK [Gathering Facts] *****************************************************************************
ok: [vm01.example.com]
TASK [task - one] **********************************************************************************
ok: [vm01.example.com] => {
"msg": "Facts variable is from vm01.example.com and myvar is variable one"
}
TASK [task - two] **********************************************************************************
ok: [vm01.example.com -> vm02.example.com] => {
"msg": "Facts variable is from vm01.example.com and myvar is variable one"
}
PLAY RECAP *****************************************************************************************
vm01.example.com : ok=3 changed=0 unreachable=0 failed=0
---
- name: play - one
hosts: vm01.example.com
vars:
- myvar: variable one
tasks:
- name: task - one
debug:
msg: Facts variable is from {{ ansible_nodename }} and myvar is {{ myvar }}
- name: task - two
debug:
msg: Facts variable is from {{ ansible_nodename }} and myvar is {{ myvar }}
delegate_to: vm02.example.com
---
- name: play one
hosts: srvgroup01
serial: 2
tasks:
- name: update installed packages
yum:
name: "*"
state: latest
- name: play two
hosts: srvgroup02
serial: 5
tasks:
- name: update installed packages
yum:
name: "*"
state: latest
---
- name: serial test
hosts: webservers
serial: 1
tasks:
- name: sleep 10 seconds
command: sleep 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment