From 5b282b1122579c9b541afe17280b6436019528da Mon Sep 17 00:00:00 2001 From: Thomas Gambier <thomas.gambier@nexedi.com> Date: Tue, 9 Nov 2021 10:59:38 +0100 Subject: [PATCH] playbook: convert vm-bootstrap scripts to python3 Also make vm-bootstrap role depends on python3 --- playbook/roles/vm-bootstrap/files/file_cmp | 4 ++-- playbook/roles/vm-bootstrap/files/format_hosts | 6 +++--- playbook/roles/vm-bootstrap/files/ping | 8 ++++---- playbook/roles/vm-bootstrap/meta/main.yml | 3 +++ 4 files changed, 12 insertions(+), 9 deletions(-) create mode 100644 playbook/roles/vm-bootstrap/meta/main.yml diff --git a/playbook/roles/vm-bootstrap/files/file_cmp b/playbook/roles/vm-bootstrap/files/file_cmp index 9b0fcbb..364ce29 100644 --- a/playbook/roles/vm-bootstrap/files/file_cmp +++ b/playbook/roles/vm-bootstrap/files/file_cmp @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import os import sys @@ -6,7 +6,7 @@ import sys if __name__ == "__main__": if len(sys.argv) < 4: - print "Use: %s FILE1 FILE2 DEST_FILE" % sys.argv[0] + print("Use: %s FILE1 FILE2 DEST_FILE" % sys.argv[0]) exit(1) file1 = sys.argv[1] diff --git a/playbook/roles/vm-bootstrap/files/format_hosts b/playbook/roles/vm-bootstrap/files/format_hosts index f9a0501..23c76b4 100644 --- a/playbook/roles/vm-bootstrap/files/format_hosts +++ b/playbook/roles/vm-bootstrap/files/format_hosts @@ -1,8 +1,8 @@ -#!/usr/bin/python +#!/usr/bin/python3 import sys -print sys.argv[1:] +print(sys.argv[1:]) host_content = open('/etc/hosts', 'r').read() hpath = sys.argv[1] @@ -13,7 +13,7 @@ for content in open(hpath, 'r').readlines(): if content: items = content.strip().split(' ') entry = "%s %s.%s %s" % (items[1], items[0], domain, items[0]) - print entry + print(entry) if not entry in host_content: lines_entry += entry + "\n" diff --git a/playbook/roles/vm-bootstrap/files/ping b/playbook/roles/vm-bootstrap/files/ping index f3a59e4..5b874a7 100644 --- a/playbook/roles/vm-bootstrap/files/ping +++ b/playbook/roles/vm-bootstrap/files/ping @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python3 import os import sys @@ -24,9 +24,9 @@ def ping_cluster(hpath): if __name__ == "__main__": if len(sys.argv) < 3: - print "Use: %s TYPE [HOST LIST] OR [HOST-FILE]" % sys.argv[0] - print "ex: %s host google.com slapos.org; %s cluster /tmp/hosts" % ( - sys.argv[0], sys.argv[0]) + print("Use: %s TYPE [HOST LIST] OR [HOST-FILE]" % sys.argv[0]) + print("ex: %s host google.com slapos.org; %s cluster /tmp/hosts" % ( + sys.argv[0], sys.argv[0])) exit(1) if sys.argv[1] == 'host': check_ping(sys.argv[2:]) diff --git a/playbook/roles/vm-bootstrap/meta/main.yml b/playbook/roles/vm-bootstrap/meta/main.yml new file mode 100644 index 0000000..b16f5ac --- /dev/null +++ b/playbook/roles/vm-bootstrap/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - { role: package, package_name: python3, package_state: present } -- 2.30.9