Add/test config changes in the random deploy test.
from random import randint
from time import sleep
-from pyinfra import facts, host, inventory
+from pyinfra import config, host, inventory
+from pyinfra.facts.server import Arch, Os
from pyinfra.operations import server
+config.SUDO = True
+
sleep(randint(1, 10) * 0.01)
server.shell(
name='First main operation',
@@ -24,20 +27,30 @@ if host.name == 'somehost':
)
# Give somehost two facts
sleep(randint(1, 10) * 0.01)
- host.get_fact(facts.server.Os)
- host.get_fact(facts.server.Arch)
+ host.get_fact(Os)
+ host.get_fact(Arch)
+
+ assert config.SUDO is True
+
elif host.name == 'anotherhost':
+ config.SUDO = False
+
sleep(randint(1, 10) * 0.01)
server.shell(
name='Second main anotherhost operation',
commands='echo second_main_op',
)
+
+ assert config.SUDO is False
+
else: # some other host
- host.get_fact(facts.server.Os)
+ host.get_fact(Os)
# Load fact from a different host
somehost = inventory.get_host('somehost')
- somehost.get_fact(facts.server.Os)
+ somehost.get_fact(Os)
+
+ assert config.SUDO is True
sleep(randint(1, 10) * 0.01)
server.shell(
