Ansible FAQ
Ansible FAQ
AnsibleUndefinedVariable: dict object has no element
我的使用了变量dc,但是后面vars/main.yml又写了dc导致重复 类似这样dc[dc] xxx 解决办法: vars/main.yml变量改成datacenter
{"reason": "We were unable to read either as JSON nor YAML, these are the errors we got from each:\nJSON: Expecting value: line 1 column 1 (char 0)\n\nSyntax Error while loading YAML.\n expected <block end>, but found '<scalar>'\n\nThe error appears to be in '/etc/ansible/roles/consul/tasks/server.yml': line 17, column 17, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n copy:\n src: {{dc}}-server-consul-0-key.pem\n ^ here\nWe could be wrong, but this one looks like it might be an issue with\nmissing quotes. Always quote template expression brackets when they\nstart a value. For instance:\n\n with_items:\n - {{ foo }}\n\nShould be written as:\n\n with_items:\n - \"{{ foo }}\"\n"}
{{}}建议都用""包起来,否则可能会报这个错 {{aa}}-afdasfd类似这种可能会报错
ansible快速测试模块或者针对服务器进行批量命令
一种是tmux同步执行,这个好处是所见即所得 ansible -m MODULE -i INVENTORY GROUP -a "PARAMS" ansible -m shell -i xxx all -a "ls /etc" 这里我还是建议优先用shell不要用command 可能会有一些奇怪的问题 因为command很多都不支持
ansible怎么放变量
只有模块需要的变量放到roles/xxx/vars/main.yml, roles/xxx/defaults/main.yml playbook定义的变量可以通过vars: xxx: xxx定义或者include_vars: /where/is/myvars.yml 每个模块都用到的,变量放到group_vars/all/main.yml 模块用到的敏感变量,也可以放到group_vars/all/main.yml
ansible 报ansible debuig mux_client_read_packet: read header failed的一种可能性
become=true改成false,如果没有sudo的需求
ansible如何从远程copy到宿主
使用fetch模块
ModuleNotFoundError: No module named 'setuptools_rust'
|
|
ansible copy too slow太慢了
使用synchronize模块
|
|
ansible stop playbook
|
|
ansible加密encrypt资产inventory
|
|
ansible查看role帮助
|
|
ansible批量下发多个命令交互
|
|
ansible uri模块报错can't concat str to bytes
uri的时候写一下
|
|
ansible里面怎么使用时间变量
|
|
使用ansible_date_time
ansible里面调用外部命令获得到变量里面
使用pipe和lookup配合 参考ansible up and running p158
|
|
ansible获取环境变量
|
|
生成一个临时密码
|
|
根据模板生成信息
|
|
ansible添加依赖模块
from p178 ansible up and running
meta/main.yml
|
|
ansible playbook指定从某个task开始
p290 ansible up and running
|
|