【发布时间】:2020-06-18 11:02:12
【问题描述】:
我正在尝试创建一个必须完成以下任务的剧本:
- 从文件file中检索主机名和版本
- 一一连接到这些主机名
- 在每个主机中检索另一个文件 another_file 的内容,该文件将为我们提供环境(dev、qa、prod)
所以我的首要任务是检索我需要连接的主机的名称
- name: retrieve nodes
shell: cat file | grep ";;" | grep foo | grep -v "bar" | sort | uniq
register: nodes
- adding nodes:
add_host:
name: "{{ item }}"
group: "servers"
with_items: "{{ nodes.stdout_lines }}"
下一个任务连接到主机
- hosts: "{{ nodes }}"
become: yes
become_user: user1
become_method: sudo
gather_facts: no
tasks:
- name: check remote file
slurp:
src: /xyz/directory/another_file
register: thing
- debug: msg="{{ thing['content'] | b64decode }}"
但它不起作用,当我添加详细信息时,我仍然看到正在执行任务的用户正在运行 playbook (local_user)
<node> ESTABLISH SSH CONNECTION FOR USER: local_user
我做错了什么?
ansible 版本是 rhel 6.1 上的 2.7.1
更新
我也用过 remote_user: user1
- hosts: "{{ nodes }}"
remote_user: user1
gather_facts: no
tasks:
- name: check remote file
slurp:
src: /xyz/directory/another_file
register: thing
- debug: msg="{{ thing['content'] | b64decode }}"
到目前为止没有运气,同样的错误
【问题讨论】:
-
你能从 cli 打开 ssh 连接吗?
ssh user1@host?这看起来像是 SSH 问题。 -
是的,ssh user1@host 无需密码也能正常工作
-
你能添加你的剧本的输出吗
标签: ansible