Last active
December 12, 2018 12:18
-
-
Save naingyeminn/65e5c39d109bd910d13c0a69aa184e58 to your computer and use it in GitHub Desktop.
Ansible Lab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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 }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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