我写的一些任务开始并且永远不会结束.Ansible不提供任何可以解释这一点的错误或日志,即使使用-vvvv选项也是如此.Playbook只是挂起,过了几个小时不会改变任何东西.
当我尝试手动运行我的任务时(通过SSH输入命令)一切都很好.
挂起的示例任务:
- name: apt upgrade
shell: apt-get upgrade
Run Code Online (Sandbox Code Playgroud)
有没有办法看到stdout和stderr?我试过了:
- name: apt upgrade
shell: apt-get upgrade
register: hello
- debug: msg="{{ hello.stdout }}"
- debug: msg="{{ hello.stderr }}"
Run Code Online (Sandbox Code Playgroud)
但没有改变.
我确实有必要的权限,我传递了正确的sudo密码 - 其他需要sudo正确执行的任务.
我正在尝试重新启动服务器,然后等待,使用此:
- name: Restart server
shell: reboot
- name: Wait for server to restart
wait_for:
port=22
delay=1
timeout=300
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
TASK: [iptables | Wait for server to restart] *********************************
fatal: [example.com] => failed to transfer file to /root/.ansible/tmp/ansible-tmp-1401138291.69-222045017562709/wait_for:
sftp> put /tmp/tmpApPR8k /root/.ansible/tmp/ansible-tmp-1401138291.69-222045017562709/wait_for
Connected to example.com.
Connection closed
Run Code Online (Sandbox Code Playgroud) 我有多个任务取决于variable1的值.我想检查值是否在{{variable1}}但我收到错误:
- name: do something when the value in variable1
command: <command>
when: "'value' in {{variable1}}"
Run Code Online (Sandbox Code Playgroud)
我正在使用ansible 2.0.2
最近我开始深入研究Ansible并编写自己的剧本.但是,我有理解become和之间的区别的麻烦become_user.据我所知它become_user是类似的su <username>,并且become意味着类似sudo su或"作为sudo用户执行所有命令".但有时这两个指令是混合的.
你能解释一下它们的正确含义吗?
我有2个app服务器,前面有一个loadbalancer,我的系统中有一个数据库服务器.我使用Ansible配置它们.应用程序服务器具有Nginx + Passenger并运行Rails应用程序.将使用capistrano进行部署,但我有一个关于ssh密钥的问题.我的git repo在另一台服务器上,我必须在appservers上生成ssh公钥并将它们添加到Git服务器(To authorized_keys文件).我怎样才能在ansible playbook中做到这一点?
PS:我可能有2台以上的app服务器.

我正在学习Ansible.我有一个清理资源的剧本,我希望剧本忽略每一个错误并一直持续到最后,如果有错误则最后失败.
我可以忽略错误
ignore_errors: yes
Run Code Online (Sandbox Code Playgroud)
如果这是一项任务,我可以做一些事情(来自ansible错误捕获)
- name: this command prints FAILED when it fails
command: /usr/bin/example-command -x -y -z
register: command_result
ignore_errors: True
- name: fail the play if the previous command did not succeed
fail: msg="the command failed"
when: "'FAILED' in command_result.stderr"
Run Code Online (Sandbox Code Playgroud)
我怎么会在最后失败?我有几个任务,我的"何时"条件是什么?
我使用ansible编写API的部署脚本.我希望这可以顺序通过我的库存文件中的每个主机,以便我可以一次完全部署到一台机器.
使用out框行为,我的playbook中的每个任务都会在清单文件中为每个主机执行,然后再继续执行下一个任务.
在下一个主机上启动之前,如何更改此行为以执行主机的所有任务?理想情况下,我想只有一本剧本.
谢谢
让我们假设一个像这样的库存文件:
node-01 ansible_ssh_host=192.168.100.101
node-02 ansible_ssh_host=192.168.100.102
node-03 ansible_ssh_host=192.168.100.103
node-04 ansible_ssh_host=192.168.100.104
node-05 ansible_ssh_host=192.168.100.105
[mainnodes]
node-[01:04]
Run Code Online (Sandbox Code Playgroud)
在我的剧本中,我现在想要创建一些包含该组IP地址的变量mainnodes:
vars:
main_nodes_ips: "192.168.100.101,192.168.100.102,192.168.100.103,192.168.100.104"
main_nodes_ips_with_port: "192.168.100.101:3000,192.168.100.102:3000,192.168.100.103:3000,192.168.100.104:3000"
Run Code Online (Sandbox Code Playgroud)
这是我到目前为止所得到的:
vars:
main_nodes_ips: "{{groups['mainnodes']|join(',')}}"
main_nodes_ips_with_port: "{{groups['mainnodes']|join(':3000,')}}"
Run Code Online (Sandbox Code Playgroud)
但那会使用主机名而不是IP地址.
有什么想法可以做到这一点?
更新:
看了一段时间的文档,我认为这将允许我遍历所有的IP地址:
{% for host in groups['mainnodes'] %}
{{hostvars[host]['ansible_ssh_host']}}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
但我无法弄清楚如何创建一个包含所有这些IP的数组.这样我就可以|join()对它们使用命令了.
Update2:
我只是觉得我已经弄明白了......但事实证明你不能在剧本中使用{%%}语法......或者我可以吗?在vars部分,它没有.:/
vars:
{% set main_nodes_ip_arr=[] %}
{% for host in groups['mesos-slave'] %}
{% if main_nodes_ip_arr.insert(loop.index,hostvars[host]['ansible_ssh_host']) %} {% endif %}
{% endfor %}
main_nodes_ips: "{{main_nodes_ip_arr|join(',')}}"
main_nodes_ips_with_port: "{{main_nodes_ip_arr|join(':3000,')}}"
Run Code Online (Sandbox Code Playgroud) 我在我的nginx-error.log文件中收到此错误:
2014/02/17 03:42:20 [crit] 5455#0: *1 connect() to unix:/tmp/uwsgi.sock failed (13: Permission denied) while connecting to upstream, client: xx.xx.x.xxx, server: localhost, request: "GET /users HTTP/1.1", upstream: "uwsgi://unix:/tmp/uwsgi.sock:", host: "EC2.amazonaws.com"
Run Code Online (Sandbox Code Playgroud)
浏览器还显示502 Bad Gateway Error.a的输出curl是相同的,Bad Gateway html
我试图通过将权限更改为/tmp/uwsgi.sock777 来修复它.这不起作用.我也把自己加入了www-data小组(一些看似相似的问题).此外,没有骰子.
这是我的nginx.conf档案:
nginx.conf
worker_processes 1;
worker_rlimit_nofile 8192;
events {
worker_connections 3000;
}
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" …Run Code Online (Sandbox Code Playgroud) 我正在运行Ansible playbook,它在一台机器上工作正常.
在我第一次尝试的新机器上,我收到以下错误.
17:04:34 PLAY [appservers] *************************************************************
17:04:34
17:04:34 GATHERING FACTS ***************************************************************
17:04:34 fatal: [server02.cit.product-ref.dev] => {'msg': "FAILED: (22, 'Invalid argument')", 'failed': True}
17:04:34 fatal: [server01.cit.product-ref.dev] => {'msg': "FAILED: (22, 'Invalid argument')", 'failed': True}
17:04:34
17:04:34 TASK: [common | remove old ansible-tmp-*] *************************************
17:04:34 FATAL: no hosts matched or all hosts have already failed -- aborting
17:04:34
17:04:34
17:04:34 PLAY RECAP ********************************************************************
17:04:34 to retry, use: --limit @/var/lib/jenkins/site.retry
17:04:34
17:04:34 server01.cit.product-ref.dev : ok=0 changed=0 unreachable=1 failed=0
17:04:34 server02.cit.product-ref.dev : ok=0 …Run Code Online (Sandbox Code Playgroud) ansible-playbook ×10
ansible ×9
ssh ×3
ansible-2.x ×2
deployment ×2
linux ×2
capistrano3 ×1
conditional ×1
flask ×1
hosts-file ×1
jinja2 ×1
nginx ×1
provisioning ×1
ubuntu ×1
uwsgi ×1