-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathon-remote.yml
69 lines (60 loc) · 1.62 KB
/
on-remote.yml
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
- name: Run script on VM hosts
gather_facts: no
hosts: vm
vars:
shell_path: "./scripts"
shell_file: "update.sh"
ignore_errors: yes
tasks:
- name: Create a temporary directory
shell: mktemp -d
register: temp_dir
- name: Push script
copy:
src: "{{ shell_path }}/{{ shell_file }}"
dest: "{{ temp_dir.stdout }}/{{ shell_file }}"
mode: '0755'
- name: Exec script
shell: "{{ temp_dir.stdout }}/{{ shell_file }}"
register: result
- name: Clean
shell: rm -rf "{{ temp_dir.stdout }}"
- name: Check result
debug:
msg: "{{ result.stdout.split('\n') }}"
- name: Exec script on LXC hosts
gather_facts: no
hosts: lxc
connection: local
vars:
shell_path: "./scripts"
shell_file: "update.sh"
ignore_errors: yes
tasks:
- name: Create a temporary directory on LXC
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "mktemp -d"
register: temp_dir
- name: Push script
pct:
cmd: "push"
host: "{{ inventory_hostname }}"
src: "{{ shell_path }}/{{ shell_file }}"
dest: "{{ temp_dir.output }}/{{ shell_file }}"
extra_args: "--perms 0755"
- name: Exec script
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "{{ temp_dir.output }}/{{ shell_file }}"
register: result
- name: Clean
pct:
cmd: "exec"
host: "{{ inventory_hostname }}"
extra_args: "rm -rf {{ temp_dir.output }}"
- name: Check result
debug:
msg: "{{ result.output.split('\n') }}"