示例playbook
[root@host131 ~]# cat msg.playbook
---
-
hosts: host131,localhost
tasks:
- name: Playbook Sample Task
debug:
msg: Welcome to Ansible
...
[root@host131 ~]#
执行结果
[root@host131 ~]# ansible-playbook msg.playbook
PLAY [host131,localhost] ***************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************
ok: [localhost]
ok: [host131]
TASK [Playbook Sample Task] ************************************************************************************************************
ok: [host131] => {
"msg": "Welcome to Ansible"
}
ok: [localhost] => {
"msg": "Welcome to Ansible"
}
PLAY RECAP *****************************************************************************************************************************
host131 : ok=2 changed=0 unreachable=0 failed=0
localhost : ok=2 changed=0 unreachable=0 failed=0
[root@host131 ~]#
方式5: 通过环境变量传给playbook的hosts
示例playbook
[root@host131 ~]# cat msg.playbook
---
-
hosts: '{{ env_host_list }}'
tasks:
- name: Playbook Sample Task
debug:
msg: Welcome to Ansible
...
[root@host131 ~]#
执行结果
[root@host131 ~]# ansible-playbook msg.playbook -e 'env_host_list=host131,localhost'
PLAY [host131,localhost] ***************************************************************************************************************
TASK [Gathering Facts] *****************************************************************************************************************
ok: [localhost]
ok: [host131]
TASK [Playbook Sample Task] ************************************************************************************************************
ok: [host131] => {
"msg": "Welcome to Ansible"
}
ok: [localhost] => {
"msg": "Welcome to Ansible"
}
PLAY RECAP *****************************************************************************************************************************
host131 : ok=2 changed=0 unreachable=0 failed=0
localhost : ok=2 changed=0 unreachable=0 failed=0
[root@host131 ~]#
————————————————
版权声明:本文为CSDN博主「淼叔」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/liumiaocn/article/details/95456872