Skip to content

Commit

Permalink
Revert "Add example showcasing how to use the ansible-inventory feature"
Browse files Browse the repository at this point in the history
This reverts commit c5ac97e.
  • Loading branch information
chungeun-choi authored and apenella committed Jan 19, 2024
1 parent f0ab3c1 commit b3dcdcc
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 0 deletions.
33 changes: 33 additions & 0 deletions examples/ansibleinventory-graph/ansibleinventory-graph.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"context"
"github.com/apenella/go-ansible/pkg/inventory"
"log"
)

func main() {
ansibleInventoryOptions := inventory.AnsibleInventoryOptions{
Graph: true,
Inventory: "inventory.yml",
Vars: true,
Yaml: true,
}

inventoryCmd := inventory.AnsibleInventoryCmd{
Pattern: "all",
Options: &ansibleInventoryOptions,
}

results, _ := inventoryCmd.Command()
log.Println("Test strings", inventoryCmd.String())
for _, result := range results {
log.Println("Command Data: ", result)
}

err := inventoryCmd.Run(context.TODO())
if err != nil {
panic(err)
}

}
22 changes: 22 additions & 0 deletions examples/ansibleinventory-graph/inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
all:
children:
webserver:
hosts:
web1:
ansible_host: 192.168.1.101
http_port: 80
max_clients: 200
web2:
ansible_host: 192.168.1.102
http_port: 80
max_clients: 150

database:
hosts:
db1:
ansible_host: 192.168.1.103
db_port: 5432
db_name: 'mydb'

vars:
ansible_user: 'admin'
32 changes: 32 additions & 0 deletions examples/ansibleinventory-simple/ansibleinventory-simple.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package main

import (
"context"
"github.com/apenella/go-ansible/pkg/inventory"
"log"
)

func main() {
ansibleInventoryOptions := inventory.AnsibleInventoryOptions{
Inventory: "inventory.yml",
List: true,
Yaml: true,
}

inventoryCmd := inventory.AnsibleInventoryCmd{
Pattern: "all",
Options: &ansibleInventoryOptions,
}

results, _ := inventoryCmd.Command()
log.Println("Test strings", inventoryCmd.String())
for _, result := range results {
log.Println("Command Data: ", result)
}

err := inventoryCmd.Run(context.TODO())
if err != nil {
panic(err)
}

}
22 changes: 22 additions & 0 deletions examples/ansibleinventory-simple/inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
all:
children:
webserver:
hosts:
web1:
ansible_host: 192.168.1.101
http_port: 80
max_clients: 200
web2:
ansible_host: 192.168.1.102
http_port: 80
max_clients: 150

database:
hosts:
db1:
ansible_host: 192.168.1.103
db_port: 5432
db_name: 'mydb'

vars:
ansible_user: 'admin'
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"context"
"github.com/apenella/go-ansible/pkg/inventory"
"log"
)

func main() {
ansibleInventoryOptions := inventory.AnsibleInventoryOptions{
Graph: true,
Inventory: "inventory.yml",
Vars: true,
Yaml: true,
VaultPasswordFile: "vault_password.cfg",
}

inventoryCmd := inventory.AnsibleInventoryCmd{
Pattern: "all",
Options: &ansibleInventoryOptions,
}

results, _ := inventoryCmd.Command()
log.Println("Test strings", inventoryCmd.String())
for _, result := range results {
log.Println("Command Data: ", result)
}

err := inventoryCmd.Run(context.TODO())
if err != nil {
panic(err)
}

}
16 changes: 16 additions & 0 deletions examples/ansibleinventory-vaulted-vars/inventory.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
all:
children:
database_servers:
hosts:
db1.example.com:
db2.example.com:
vars:
ansible_ssh_user: dbadmin
ansible_ssh_pass: !vault |
$ANSIBLE_VAULT;1.1;AES256
35666433353234313161636238653633313264383230316233656236313935313465666533646164
3039353461343961616134653164666663646362646336360a383332663562396237613264386636
66663233616235396662383434343966333665383937653839326633333861366162616365353533
6237653031613664340a383736643130303935633164366536363561663334643763343661666138
62343234643536663061316666626466343265353065333439643065313134633132
db_port: 5432
1 change: 1 addition & 0 deletions examples/ansibleinventory-vaulted-vars/vault_password.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ThatIsAPassword

0 comments on commit b3dcdcc

Please sign in to comment.