Skip to content

Commit 30cca71

Browse files
committed
use python3 f strings to cleanup string interpolation
1 parent 0df52ae commit 30cca71

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

inventory/vagrants/inventory_dir/centos.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
# NOTE: this file must be executable `chmod +x centos.py`
33
# challenge: make this file not executable and see what `ansible-inventory --list` prints
44

@@ -24,11 +24,12 @@
2424
# challenge: port ubuntu static inventory to script too
2525
# challenge: port centos.py script (this file) back into static inventory
2626
for i in range(2):
27-
inventory["_meta"]["hostvars"]["centos2{:d}".format(i)] = {
28-
"ansible_host": "192.168.50.2{:d}".format(i),
29-
"ansible_private_key_file": ".vagrant/machines/centos2{:d}/virtualbox/private_key".format(i)
27+
host = f"centos2{i}"
28+
inventory["_meta"]["hostvars"][host] = {
29+
"ansible_host": f"192.168.50.2{i}",
30+
"ansible_private_key_file": f".vagrant/machines/{host}/virtualbox/private_key"
3031
}
31-
inventory["centos"]["hosts"].append("centos2{:d}".format(i))
32+
inventory["centos"]["hosts"].append(host)
3233

3334
# python json API https://docs.python.org/3/library/json.html
3435
# script returns inventory formatted as json to ansible

0 commit comments

Comments
 (0)