Skip to content

Commit

Permalink
ansibleplaybook-ssh-become-root-with-password: enable choose ansible-…
Browse files Browse the repository at this point in the history
…core version
  • Loading branch information
apenella committed Oct 16, 2024
1 parent 3b3e083 commit 1715a3c
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 26 deletions.
3 changes: 2 additions & 1 deletion examples/ansibleplaybook-ssh-become-root-with-password/.env
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
GOLANG_VERSION=1.22
GOLANG_VERSION=1.22
ANSIBLE_CORE_VERSION=2.16.9
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ attach-server: ## Attach to the server container
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

_run:
@$(DOCKER_COMPOSE_BINARY) --project-name $(PROJECT_NAME) exec --workdir /code/examples/$$(basename $$(pwd)) ansible go run $$(basename $$(pwd)).go || true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"github.com/apenella/go-ansible/v2/pkg/playbook"
)

// ansible-playbook -i inventory.yml site.yml --extra-vars '{"ansible_ssh_private_key_file":"/ssh/id_rsa","ansible_sudo_pass":"12345"}' --ssh-common-args '-o UserKnownHostsFile=/dev/null' --ssh-extra-args '-o StrictHostKeyChecking=accept-new' --timeout 300 --user aleix --become-method sudo --become-user root

func main() {
ansiblePlaybookOptions := &playbook.AnsiblePlaybookOptions{
Become: true,
Expand All @@ -33,18 +31,6 @@ func main() {
playbook.WithPlaybookOptions(ansiblePlaybookOptions),
)

// exec := stdoutcallback.NewYAMLStdoutCallbackExecute(

// )

// exec := configuration.NewAnsibleWithConfigurationSettingsExecute(
// execute.NewDefaultExecute(
// execute.WithCmd(cmd),
// execute.WithErrorEnrich(playbook.NewAnsiblePlaybookErrorEnrich()),
// ),
// configuration.WithAnsibleForceColor(),
// ),

exec := configuration.NewAnsibleWithConfigurationSettingsExecute(
execute.NewDefaultExecute(
execute.WithCmd(cmd),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ services:
context: docker/ansible
args:
- golang_version=${GOLANG_VERSION}
- ansible_core_version=${ANSIBLE_CORE_VERSION}
command: ["tail", "-f", "/dev/null"]
# command: ["ansible-playbook", "--help"]
volumes:
- ssh:/ssh
- ../..:/code
Expand All @@ -20,7 +20,6 @@ services:
server:
build:
context: docker/server
# command: ["cat", "/etc/ssh/sshd_config"]
volumes:
- ssh:/ssh
depends_on:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ FROM golang:${golang_version}-bookworm as golang

FROM python:3.12-alpine3.19

ARG ansible_core_version=2.16.9

RUN apk add --update --no-cache \
openssh-client \
git \
Expand All @@ -15,8 +17,9 @@ RUN pip3 install -U pip setuptools \
cryptography \
# Required library to execute ansible community.general.dig plugin
dnspython \
ansible \
&& ln /usr/local/bin/ansible-playbook /usr/bin/ansible-playbook
ansible-core==${ansible_core_version} \
&& ln /usr/local/bin/ansible-playbook /usr/bin/ansible-playbook \
&& ansible-galaxy collection install community.general

COPY --from=golang /usr/local/go /usr/local/go

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ echo "aleix ALL=(ALL:ALL) ALL" >> /etc/sudoers

## -e option will print the logs to the console
/usr/sbin/sshd -D -e
# /usr/sbin/sshd -D
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,3 @@ all:
hosts:
server:
ansible_host: server
# ansible_user: aleix
# ansible_ssh_private_key_file: /ssh/id_rsa
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- name: ansibleplaybook-ssh
ansible.builtin.debug:
msg: |
Your are running 'ansibleplaybook-ssh-sudo' example
Your are running 'ansibleplaybook-ssh-become-root-with-password' example
Remote server IP is: {{ hostvars['server']['ansible_facts']['eth0']['ipv4']['address'] }}
Expand Down

0 comments on commit 1715a3c

Please sign in to comment.