标签:文件中 yum安装 code 实现 cat 指定 输出 使用 image
name: test
hosts: 192.168.190.133
vars:
test_user: zhangsan 对test_user变量赋值
tasks:
- name: add user
user:
name: ‘{{ test_user }}‘ 定义变量,变量名为:test_user
state: present
[root@localhost project]# ansible-playbook -i inventory -e ‘test_user=zhangsan‘ playbook/ceshi1.yml -e 选项后把zhangsan赋值给变量test_user。
[root@localhost project]# cat host_vars/192.168.190.133/vars
ansible_password: 123456 为ansible_password变量配置密码
[root@localhost project]# ansible-playbook -i inventory -e ‘test_user=zhangsan‘ playbook/ceshi1.yml 运行playbook -i指定对应的清单
对playbook中的某一任务的结果存入到变量中,其后用debug模块调用此变量。
[root@localhost project]# vim playbook/ceshi1.yml
---
- hosts: 192.168.190.134
tasks:
- name: yum install and register
yum:
name: vsftpd
state: present
register: install_log 新建install_log变量,并把yum安装输出内容赋值其中。
- debug: var=install_log 输出变量中内容
TASK [debug] *******************************************************************
ok: [192.168.190.134] => {
"install_log": {
"changed": true,
"failed": false,
"msg": "Check mode: No changes made, but would have if not in check mode",
"rc": 0,
"results": []
}
}
......
标签:文件中 yum安装 code 实现 cat 指定 输出 使用 image
原文地址:https://www.cnblogs.com/sawyer95/p/13597884.html