forked from pyinfra-dev/pyinfra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasics.py
More file actions
83 lines (71 loc) · 1.61 KB
/
basics.py
File metadata and controls
83 lines (71 loc) · 1.61 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
from pyinfra import host
from pyinfra.modules import files, server
# Executing as the SSH user (vagrant):
#
# Generate files from local jinja2 templates
files.template(
{'Generate/upload templates/template.txt.j2'},
'templates/template.txt.j2',
'/home/vagrant/template.txt',
)
server.shell(
{'Execute some shell commands'},
[
'echo "Shell command"',
'echo "My hostname is {{ host.fact.hostname }}"',
],
)
# and scripts
server.script(
{'Run the files/test.sh script'},
'files/test.sh',
)
# Copy local files to remote host
files.put(
{'Upload files/file.txt'},
'files/file.txt',
'/home/vagrant/file.txt',
mode=777,
)
# and sync directories
files.sync(
{'Sync the files directory'},
'files',
'/home/vagrant/example_files',
delete=True,
)
# Executing with sudo
#
# Ensure the state of a user
server.user(
{'Ensure pyinfra user exists'},
'pyinfra',
shell='/bin/sh',
# Global arguments available in all operations, for the full list see:
# https://pyinfra.readthedocs.io/page/deploys.html#global-arguments
sudo=True,
)
# And groups
server.group(
{'Ensure pyinfra2 group exists'}, # use a set as the first arg to set the op name
'pyinfra2',
sudo=True,
)
# Ensure the state of files
files.file(
{'Ensure pyinfra.log exists'},
'/var/log/pyinfra.log',
user='pyinfra',
group='pyinfra',
mode=644,
sudo=True,
)
# Ensure the state of directories
files.directory(
{'Ensure {{ host.data.env_dir }} exists exists'},
host.data.env_dir,
user='pyinfra',
group='pyinfra',
mode=755,
sudo=True,
)