from pyinfra.operations import files
# Download a file
files.download(
name="Download the Docker repo file",
src="https://download.docker.com/linux/centos/docker-ce.repo",
dest="/etc/yum.repos.d/docker-ce.repo",
)
# Upload a file
files.put(
name="Update the message of the day file",
src="files/motd",
dest="/etc/motd",
mode="644",
)
# Create a templated file
files.template(
name="Create a templated file",
src="templates/somefile.conf.j2",
dest="/etc/somefile.conf",
)
# Ensure a line in a file
files.line(
name="Add the down-for-maintenance line in /etc/motd",
path="/etc/motd",
line="SYSTEM IS DOWN FOR MAINTENANCE",
)
# Create a directory
files.directory(
name="Ensure /opt/myapp exists",
path="/opt/myapp",
mode="755",
user="www-data",
group="www-data",
)