首页
学习
活动
专区
圈层
工具
发布

带凹角
EN

Stack Overflow用户
提问于 2019-11-18 12:58:45
回答 1查看 1.6K关注 0票数 1

我正试图在Concourse中为远程主机运行ansible剧本,但是我不能这样做。以下是我的步骤:-

汇合Yaml档案:-

代码语言:javascript
复制
---
resource_types:
- name: ansible-playbook
  type: docker-image
  source:
    repository: troykinsella/concourse-ansible-playbook-resource
    tag: latest

resources:
- name: ansible
  type: ansible-playbook
  source:
    debug: true
    user: cloud_user
    ssh_private_key: ((ssh-key))
    verbose: vvv

- name: source-code
  type: git
  source:
    uri: ((git-repo))
    branch: master
    private_key: ((ssh-key))

jobs:
  - name: ansible-concourse
    plan:
    - get: source-code # git resource
    - put: ansible
      params:
        check: true
        diff: true
        become: true
        become_user: root
        inventory: inventory/hosts
        playbook: site.yml
        path: source-code

主机档案:-

代码语言:javascript
复制
[test]
localhost

货柜内:-

我拦截了集装箱,我可以ssh到任何IP内部,但我不能做ssh-登录。

游戏指南:-

代码语言:javascript
复制
---
- name: "Running Current Working Directory"
  hosts: test
  gather_facts: no

  tasks:
     - name: "Current Working Directory"
       shell: pwd
       register: value

     - debug:
          msg: "The Current Working Directory {{value.stdout_lines}}"

进场输出:-

代码语言:javascript
复制
ansible-playbook       -i inventory/hosts --private-key /tmp/ansible-playbook-resource-ssh-private-key   --user cloud_user   -vvv site.yml
ansible-playbook 2.9.0
  config file = /tmp/build/put/source-code/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python3.6/dist-packages/ansible
  executable location = /usr/local/bin/ansible-playbook
  python version = 3.6.8 (default, Oct  7 2019, 12:59:55) [GCC 8.3.0]
Using /tmp/build/put/source-code/ansible.cfg as config file
host_list declined parsing /tmp/build/put/source-code/inventory/hosts as it did not pass its verify_file() method
script declined parsing /tmp/build/put/source-code/inventory/hosts as it did not pass its verify_file() method
auto declined parsing /tmp/build/put/source-code/inventory/hosts as it did not pass its verify_file() method
Parsed /tmp/build/put/source-code/inventory/hosts inventory source with ini plugin

PLAYBOOK: site.yml *************************************************************
1 plays in site.yml

PLAY [Running Current Working Directory] ***************************************
META: ran handlers

TASK [Current Working Directory] ***********************************************
task path: /tmp/build/put/source-code/site.yml:7
Monday 18 November 2019  12:38:49 +0000 (0:00:00.084)       0:00:00.085 ******* 
<localhost> ESTABLISH SSH CONNECTION FOR USER: cloud_user
<localhost> SSH: EXEC ssh -C -o ControlMaster=auto -o ControlPersist=60s -o 'IdentityFile="/tmp/ansible-playbook-resource-ssh-private-key"' -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 'User="cloud_user"' -o ConnectTimeout=10 -o ControlPath=/root/.ansible/cp/dc52b3112c localhost '/bin/sh -c '"'"'echo ~cloud_user && sleep 0'"'"''
<localhost> (255, b'', b'')
fatal: [localhost]: UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: ",
    "unreachable": true
}

PLAY RECAP *********************************************************************
localhost                  : ok=0    changed=0    unreachable=1    failed=0    skipped=0    rescued=0    ignored=0   

Monday 18 November 2019  12:38:49 +0000 (0:00:00.029)       0:00:00.114 ******* 
=============================================================================== 
Current Working Directory ----------------------------------------------- 0.03s
/tmp/build/put/source-code/site.yml:7 -----------------------------------------
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-11-18 13:50:15

localhost通常是通过local connection plugin访问的(除非您试图做一些非常特殊的事情,并且您已经通过ssh配置了访问权限,从上面的错误消息来看,这种情况似乎并非如此)。

如果您没有在库存中声明它,localhost是隐式的,使用local连接,并且在all组中不匹配。

但是,如果在库存中显式声明localhost,则default connection plugin becomes sshall组也与此主机匹配。在这种情况下,您必须自己将连接设置为local

您有两个选项可以使当前的测试工作:

删除库存(或使用未显式声明hosts: localhost

  • Keep的目录),修改操作手册以直接针对localhost,按原样进行localhost,并修改库存测试本地主机ansible_connection=local

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58915108

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档