disable gitignore, use ini inventory to avoid pyyaml
This commit is contained in:
		
							parent
							
								
									9cfe1f008f
								
							
						
					
					
						commit
						f0031c427e
					
				
					 3 changed files with 8 additions and 11 deletions
				
			
		
							
								
								
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
										
									
									
										vendored
									
									
								
							| 
						 | 
					@ -1,2 +0,0 @@
 | 
				
			||||||
.venv
 | 
					 | 
				
			||||||
inventory.yaml
 | 
					 | 
				
			||||||
							
								
								
									
										15
									
								
								mkinv
									
										
									
									
									
								
							
							
						
						
									
										15
									
								
								mkinv
									
										
									
									
									
								
							| 
						 | 
					@ -1,20 +1,19 @@
 | 
				
			||||||
#!/usr/bin/env python3
 | 
					#!/usr/bin/env python3
 | 
				
			||||||
import sys
 | 
					import sys
 | 
				
			||||||
import yaml
 | 
					
 | 
				
			||||||
 | 
					FILENAME = "./inventory.ini"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def main():
 | 
					def main():
 | 
				
			||||||
    hosts = {}
 | 
					    hosts = []
 | 
				
			||||||
    counter = 0
 | 
					    counter = 0
 | 
				
			||||||
    for addr in sys.argv[1:]:
 | 
					    for addr in sys.argv[1:]:
 | 
				
			||||||
        hosts[f"vm{counter}"] = { "ansible_host": addr }
 | 
					        hosts.append(f"vm{counter} ansible_host={addr}")
 | 
				
			||||||
        counter += 1
 | 
					        counter += 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    inventory = { "all": { "hosts": hosts } }
 | 
					    inventory = "\n".join(hosts)
 | 
				
			||||||
    inventory_yaml = yaml.dump(inventory)
 | 
					    with open(FILENAME, "w", encoding="utf8") as inv_file:
 | 
				
			||||||
    print(inventory_yaml)
 | 
					        inv_file.write(inventory + "\n")
 | 
				
			||||||
#   with open("./inventory.yaml", "w", encoding="utf8") as inv_file:
 | 
					 | 
				
			||||||
#       inv_file.write(inventory_yaml)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if __name__ == "__main__":
 | 
					if __name__ == "__main__":
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,7 +18,7 @@ http {
 | 
				
			||||||
  server {
 | 
					  server {
 | 
				
			||||||
    listen 80 default_server;
 | 
					    listen 80 default_server;
 | 
				
			||||||
    location / {
 | 
					    location / {
 | 
				
			||||||
      return 200 ">>>>>>>>>> I am {{ inventory_hostname }} ({{ ipv4.address }}) <<<<<<<<<<\n";
 | 
					      return 200 ">>>>>>>>>> I am {{ inventory_hostname }} ({{ ansible_host }}) <<<<<<<<<<\n";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue