Skip to content

Commit

Permalink
Update the examples to use the imported config object.
Browse files Browse the repository at this point in the history
  • Loading branch information
Fizzadar committed Nov 1, 2021
1 parent 950e2bb commit 87a0ea4
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 37 deletions.
4 changes: 2 additions & 2 deletions examples/digitalocean/remove_10_ip.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pyinfra import host
from pyinfra import config, host
from pyinfra.facts.hardware import Ipv4Addresses
from pyinfra.operations import server

SUDO = True
config.SUDO = True

ip = host.get_fact(Ipv4Addresses)['eth0']

Expand Down
9 changes: 6 additions & 3 deletions examples/docker_ce.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyinfra import host
from pyinfra import config, host
from pyinfra.facts.server import LinuxName, LsbRelease
from pyinfra.operations import apt, init, python

Expand All @@ -9,14 +9,17 @@
# Please see https://github.com/Fizzadar/pyinfra-docker
# for a more complete pyinfra docker installation.

SUDO = True
config.SUDO = True
# If the remote system requires a password for sudo, un-comment the line below:
# USE_SUDO_PASSWORD = True


def check_docker_works(state, host):
command = 'docker run hello-world'
status, stdout, stderr = host.run_shell_command(command=command, sudo=SUDO)
status, stdout, stderr = host.run_shell_command(
command=command,
sudo=config.SUDO,
)
if not status or 'Hello from Docker!' not in stdout:
raise Exception('`{}` did not work as expected'.format(command))

Expand Down
4 changes: 2 additions & 2 deletions examples/files_download.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pyinfra import host
from pyinfra import config, host
from pyinfra.facts.server import LinuxName
from pyinfra.operations import apt, files

SUDO = True
config.SUDO = True

if host.get_fact(LinuxName) == 'Ubuntu':

Expand Down
3 changes: 2 additions & 1 deletion examples/files_line_with_quotes.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pyinfra import config
from pyinfra.operations import files

SUDO = True
config.SUDO = True

# Run: pyinfra @docker/ubuntu files_line_with_quotes.py

Expand Down
4 changes: 2 additions & 2 deletions examples/puppet/step0.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pyinfra import host
from pyinfra import config, host
from pyinfra.facts.hardware import Ipv4Addresses
from pyinfra.operations import server

SUDO = True
config.SUDO = True

ip = host.get_fact(Ipv4Addresses)['eth0']

Expand Down
4 changes: 2 additions & 2 deletions examples/puppet/step1.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pyinfra import host, inventory
from pyinfra import config, host, inventory
from pyinfra.facts.hardware import Ipv4Addresses
from pyinfra.facts.server import LinuxDistribution, LinuxName
from pyinfra.operations import files, init, server, yum

SUDO = True
config.SUDO = True


# update the /etc/hosts file
Expand Down
6 changes: 3 additions & 3 deletions examples/puppet/step2.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pyinfra import host, inventory
from pyinfra import config, host, inventory
from pyinfra.operations import init, puppet, server

SUDO = True
USE_SUDO_LOGIN = True
config.SUDO = True
config.USE_SUDO_LOGIN = True

if host in inventory.get_group('master_servers'):
server.script_template(
Expand Down
6 changes: 3 additions & 3 deletions examples/puppet/step3.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pyinfra import host, inventory
from pyinfra import config, host, inventory
from pyinfra.operations import files, puppet

SUDO = True
USE_SUDO_LOGIN = True
config.SUDO = True
config.USE_SUDO_LOGIN = True

if host in inventory.get_group('master_servers'):
files.template(
Expand Down
4 changes: 2 additions & 2 deletions examples/pxe/pxe_infra.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pyinfra import host
from pyinfra import config, host
from pyinfra.facts.server import LinuxName
from pyinfra.operations import apt, files, init, server

SUDO = True
config.SUDO = True

# If you change pxe_server value below then check/change Vagrantfile
pxe_server = '192.168.0.240'
Expand Down
4 changes: 2 additions & 2 deletions examples/pxe_with_nfs/pxe_with_nfs_infra.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from pyinfra import host
from pyinfra import config, host
from pyinfra.facts.files import File
from pyinfra.facts.server import LinuxName
from pyinfra.operations import apt, files, init, server

SUDO = True
config.SUDO = True

# If you change pxe_server value below then check/change Vagrantfile
pxe_server = '192.168.0.240'
Expand Down
4 changes: 2 additions & 2 deletions examples/python_webserver/myweb.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from pyinfra import host
from pyinfra import config, host
from pyinfra.facts.server import LinuxName
from pyinfra.operations import files, init, server

SUDO = True
config.SUDO = True

if host.get_fact(LinuxName) in ['Ubuntu']:

Expand Down
3 changes: 2 additions & 1 deletion examples/server_outputs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from pyinfra import config
from pyinfra.operations import server

SUDO = True
config.SUDO = True

# Various different outputs

Expand Down
4 changes: 2 additions & 2 deletions examples/ssh_demo/ssh_demo1.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pyinfra import host, inventory
from pyinfra import config, host, inventory
from pyinfra.operations import files, server

SUDO = True
config.SUDO = True


# update the /etc/hosts file
Expand Down
4 changes: 2 additions & 2 deletions examples/ssh_demo/ssh_demo2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pyinfra import host
from pyinfra import config, host
from pyinfra.operations import server

SUDO = True
config.SUDO = True

if host.name == '@vagrant/two':

Expand Down
5 changes: 3 additions & 2 deletions examples/user_sudo_su.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pyinfra import config
from pyinfra.operations import files, server

SUDO = True
FAIL_PERCENT = 0
config.SUDO = True
config.FAIL_PERCENT = 0


server.user(
Expand Down
6 changes: 3 additions & 3 deletions examples/vagrant/vagrant.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from pyinfra import host
from pyinfra import config, host
from pyinfra.facts.server import LinuxName
from pyinfra.operations import apt, files, python, server

SUDO = True
config.SUDO = True


def verify_vagrant(state, host):
command = 'vagrant --version'
status, stdout, stderr = host.run_shell_command(state, command=command, sudo=SUDO)
status, stdout, stderr = host.run_shell_command(state, command=command, sudo=config.SUDO)
assert status is True # ensure the command executed OK
if 'Vagrant ' not in str(stdout):
raise Exception('`{}` did not work as expected.stdout:{} stderr:{}'.format(
Expand Down
6 changes: 3 additions & 3 deletions examples/virtualbox/virtualbox.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from pyinfra import host
from pyinfra import config, host
from pyinfra.facts.server import LinuxDistribution, LinuxName, OsVersion
from pyinfra.operations import apt, python, server

SUDO = True
config.SUDO = True

virtualbox_version = '6.1'


def verify_virtualbox_version(state, host, version):
command = '/usr/bin/virtualbox --help'
status, stdout, stderr = host.run_shell_command(state, command=command, sudo=SUDO)
status, stdout, stderr = host.run_shell_command(state, command=command, sudo=config.SUDO)
assert status is True # ensure the command executed OK
if version not in str(stdout):
raise Exception('`{}` did not work as expected.stdout:{} stderr:{}'.format(
Expand Down

0 comments on commit 87a0ea4

Please sign in to comment.