local_action的核心作用就是在运行playbook时,让指定任务在ansible控制节点上执行,而不是远程目标主机上执...
shell:echo"test">/root/test.list delegate_to: 172.16.60.245 则上面的shell模块的task任务只会在172.16.60.245这台节点上执行,test_server组内其他的机器不会执行shell任务。 --- 如果"delegate_to: 127.0.0.1"则可以用local_action来代替。即下面两个配置效果是一样的!! [root@hostname~]# cat /etc/ans...
- name: start_nginx shell: /usr/local/nginx/sbin/nginx - name: stop_nginx shell: /usr/local/nginx/sbin/nginx -s stop - name: reload_nginx shell: /usr/local/nginx/sbin/nginx -s reload 1. 2. 3. 4. 5. 6. 7. 8. (3) 在roles/nginx/tasks/main.yaml下添加添加notify任务 特别提示:...
local_action: shell if [ ! "`ls -A {{uatMongo8449BackupDir}}/{{date.stdout}}`" = "" ]; then echo '{{date.stdout}}:successful:uatMongo8449' >> {{statusFile}} ; else echo '{{date.stdout}}:failed:uatMongo8449' >> {{statusFile}} ; fi args: warn: no 1. 2. 3. 4. 5....
delegate_to 、connection 、local_action 使用场景 由于工作需要,经常需要把目标节点获得的信息写入执行节点文件日志。 所以经常用到delegate_to和connection,而local_action写法难看,基本不用。 delegate_to和connection最后达到的目标是一致的, 就是把目标服务器上的{{ }}大括号标记的变量在代理连接的节点(delegate_to...
- name: local_action local_action: shell echo "local_action. {{inventory_hostname}} $(hostname)" >> /tmp/local.log 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 这个例子中,依次使用了connection、delegate_to和local_action三种方式,还使用了一个变量{{inventory_hostname}},这是ansible...
- name: get status local_action : command 'get k8s status' run_once run_once: true来指定该task只能在某一台机器上执行一次. 可以和delegate_to 结合使用,指定在"192.168.0.9"上执行一次升级数据库操作 - command: /opt/upgrade_db.py run_once: true delegate_to: "192.168.0.9" ...
Currently only used for remote coverage on PowerShell modules. This is for internal use only. Type: str Default: * Version Added: 2.9 Environment: Variable: _ANSIBLE_COVERAGE_REMOTE_PATH_FILTER DEFAULT_ACTION_PLUGIN_PATH Description: Colon-separated paths in which Ansible will search ...
local_tmp #上述工作原理中提到本地生成脚本存放的临时目录 forks #并发连接数,默认为5sudo_user #命令执行用户 remote_port #访问管理主机的端口 host_key_checking #设置是否检查SSH主机的密钥,默认为falsetimeout #ssh连接被管理主机的超时时间 log_path #ansilbe日志文件路径 ...
在异步模式下,如果设置的检查时间间隔为0,在将每一批节点的任务丢到后台后都会立即返回ansible,并立即将下一批节点的任务丢到后台,直到所有任务都丢到后台完后,才返回ansible端,ansible才会立即释放占用的shell。即此时ansible是不会管各个节点任务执行情况的,不管执行成功或失败。因此在轮训检查时间内,ansible仍然正在运...