如何在docker容器内运行一个可用的脚本?

时间:2023-01-15 20:45:46

I am using docker for testing my playbooks.

我正在使用docker来测试我的剧本。

I created a container now when i am running below command inside container its giving me below error

我现在创建了一个容器,当我运行在容器内的命令下时,它给出了下面的错误

ansible-playbook jenkins.yml

ansible-playbook jenkins.yml

Error:-

错误:-

[root@db1e9105692d jenkins-playbook]# ansible-playbook  jenkins.yml -k -vvv
SSH password:

PLAY [localhost] **************************************************************

GATHERING FACTS ***************************************************************
<localhost> ESTABLISH CONNECTION FOR USER: root
<localhost> REMOTE_MODULE setup
<localhost> EXEC sshpass -d4 ssh -C -tt -v -o ControlMaster=auto -o ControlPersist=60s -o ControlPath="/root/.ansible/cp/ansible-ssh-%h-%p-%r" -o StrictHostKeyChecking=no -o GSSAPIAuthentication=no -o PubkeyAuthentication=no -o ConnectTimeout=10 localhost /bin/sh -c 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1454580537.38-114451000565344 && echo $HOME/.ansible/tmp/ansible-tmp-1454580537.38-114451000565344'
EXEC previous known host file not found for localhost
fatal: [localhost] => SSH Error: ssh: connect to host localhost port 22: Connection refused
    while connecting to 127.0.0.1:22
It is sometimes useful to re-run the command using -vvvv, which prints SSH debug output to help diagnose the issue.

TASK: [jenkins | Include OS-Specific variables] *******************************
<localhost> ESTABLISH CONNECTION FOR USER: root
fatal: [localhost] => One or more undefined variables: 'ansible_os_family' is undefined

FATAL: all hosts have already failed -- aborting

PLAY RECAP ********************************************************************
           to retry, use: --limit @/root/jenkins.retry

localhost                  : ok=0    changed=0    unreachable=2    failed=0

But if i run this command on host machine its running fine.Do i need to do anything so that connection do not gets refused on port 22.inside docker container

但是如果我在主机上运行这个命令,它就运行得很好。我是否需要做任何事情,以使连接在端口22上不会被拒绝。在集装箱码头工人

Please do not consider below line as reason for error.Its just that ansible has executed few more lines before throwing error. Actually its not able to run so thats why value of this variable is empty.

请不要认为以下行是错误的原因。它只是在抛出错误之前已经执行了几行。实际上它不能运行,这就是为什么这个变量的值是空的。

fatal: [localhost] => One or more undefined variables: 'ansible_os_family' is undefined

2 个解决方案

#1


3  

In your container start your playbook locally:

在您的容器中,在本地启动您的剧本:

$ ansible-playbook jenkins.yml -c local -k -vvv

#2


0  

Do you have connection=local defined for localhost? It's trying to connect via ssh, which can not work because you probably do not have sshd running in your container.

是否为localhost定义了connection=local ?它正在尝试通过ssh连接,这无法工作,因为您的容器中可能没有运行sshd。

#1


3  

In your container start your playbook locally:

在您的容器中,在本地启动您的剧本:

$ ansible-playbook jenkins.yml -c local -k -vvv

#2


0  

Do you have connection=local defined for localhost? It's trying to connect via ssh, which can not work because you probably do not have sshd running in your container.

是否为localhost定义了connection=local ?它正在尝试通过ssh连接,这无法工作,因为您的容器中可能没有运行sshd。