Skip to content

Commit

Permalink
improve ansibleplaybook-extravars example
Browse files Browse the repository at this point in the history
  • Loading branch information
apenella committed Mar 22, 2024
1 parent 3c7c882 commit a8ce3f7
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion examples/ansibleplaybook-extravars/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ project-name: ## Show the project name
@echo $(PROJECT_NAME)

run: ## Run the playbook
@$(DOCKER_COMPOSE_BINARY) --project-name $(PROJECT_NAME) exec --workdir /code/examples/$$(basename $$(pwd)) ansible go run ansibleplaybook-ssh.go
@$(DOCKER_COMPOSE_BINARY) --project-name $(PROJECT_NAME) exec --workdir /code/examples/$$(basename $$(pwd)) ansible go run $$(basename $$(pwd)).go
13 changes: 8 additions & 5 deletions examples/ansibleplaybook-extravars/ansibleplaybook-extravars.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/apenella/go-ansible/v2/pkg/execute"
"github.com/apenella/go-ansible/v2/pkg/execute/stdoutcallback"
"github.com/apenella/go-ansible/v2/pkg/playbook"
)

Expand All @@ -25,13 +26,15 @@ func main() {
playbook.WithPlaybookOptions(ansiblePlaybookOptions),
)

exec := execute.NewDefaultExecute(
execute.WithCmd(playbookCmd),
)

fmt.Println("Command: ", playbookCmd.String())

Check failure

Code scanning / CodeQL

Clear-text logging of sensitive information High

Sensitive data returned by an access to VaultPasswordFile
flows to a logging call.

err := exec.Execute(context.TODO())
yamlexec := stdoutcallback.NewYAMLStdoutCallbackExecute(
execute.NewDefaultExecute(
execute.WithCmd(playbookCmd),
),
)

err := yamlexec.Execute(context.TODO())
if err != nil {
panic(err)
}
Expand Down
10 changes: 8 additions & 2 deletions examples/ansibleplaybook-extravars/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,14 @@
extravar2: na

tasks:
- name: Gather facts
ansible.builtin.setup:
gather_subset:
- all_ipv4_addresses

- name: show values
debug:
msg: |
{{ extravar1 }}
{{ extravar2 }}
{{ hostvars['server']['ansible_hostname'] }}[{{ hostvars['server']['ansible_default_ipv4']['address'] }}] (port: {{ hostvars['server']['ansible_port'] }})
- {{ extravar1 }}
- {{ extravar2 }}

0 comments on commit a8ce3f7

Please sign in to comment.