Ansible 2.1 版
我有一个库存文件 hosts
[nodes]
host1
host2
...
Run Code Online (Sandbox Code Playgroud)
和一个简单的剧本 site.yml
---
- hosts: all
tasks:
- include: tasks/main.yml
Run Code Online (Sandbox Code Playgroud)
如果我刚开始玩
ansible-playbook -i hosts site.yml -vvvv
Run Code Online (Sandbox Code Playgroud)
我收到所有主机的这个错误,
ESTABLISH SSH CONNECTION FOR USER: None
fatal: [host1]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh.", "unreachable": true}
...
Run Code Online (Sandbox Code Playgroud)
然而,阅读Ansible Inventory文档,我添加ansible_user到hosts文件中,
[nodes]
host1 ansible_user=root
host2 ansible_user=root
...
Run Code Online (Sandbox Code Playgroud)
这解决了SSH CONNECTION UNREACHABLE错误。但是,我必须ansible_user=root在所有主机旁边添加吗?或者有没有更简单的方法来做到这一点?
2.1 版
在剧本中,我开始了一个过程:
- name: Start Automation Agent, and enable start on boot
service: name=mongodb-mms-automation-agent state=started enabled=yes
Run Code Online (Sandbox Code Playgroud)
从播放回顾来看,该过程似乎已成功启动。
TASK [install : Start automation agent, and enable start on boot] **************
changed: [server1]
Run Code Online (Sandbox Code Playgroud)
但是,当登录到远程主机并执行 a 时ps,该进程并未运行。检查进程日志它没有通过一些先决条件(预期)。
如何在剧本中编写任务以确认流程已成功启动?
我已经在 VMware Player 虚拟机中安装了 64 位版本的 Ubuntu Minimal 14.04。Ubuntu Minimal 只有我喜欢的 CLI(命令行界面),但我不知道如何在终端中复制/粘贴。我特别需要粘贴,因为我需要运行的一些链接太长而无法手动输入。
我试过Ctrl+ V, Ctrl+ Shift+ V, Shift+ Insert, Ctrl+ Shift+ Insert,但到目前为止还没有运气。如何在 CLI 中复制/粘贴?
Ansible 2.1
Ansible 主机:Ubuntu 16.04
远程主机:CentOS 6.5
我对 Ansible 很陌生。我有一个简单的ansible项目:
??? hosts
??? roles
? ??? setup
? ??? defaults
? ? ??? main.yml
? ??? tasks
? ? ??? main.yml
? ??? templates
? ??? automation-agent.config.j2
??? site.yml
Run Code Online (Sandbox Code Playgroud)
我用来运行剧本的命令:
ansible-playbook -i hosts site.yml --user admin --ask-pass
在远程主机上,我设置了admin具有 root 权限的用户:
root ALL=(ALL) ALL
admin ALL=(ALL) ALL
Run Code Online (Sandbox Code Playgroud)
但是,其中一项剧本任务遇到了问题:
- name: Back up Automation Agent config file if exists
command: mv /etc/mongodb-mms/automation-agent.config /etc/mongodb-mms/automation-agent.config.bak
Run Code Online (Sandbox Code Playgroud)
Ansible 报告:
TASK [setup : Back up …Run Code Online (Sandbox Code Playgroud)