我有一本剧本,我想从中扮演两个角色:
所以在第一本剧本中,我使用" ec2"模块,返回大量信息,包括其ip。
我可以以某种方式将此ip传递给下一个角色吗?
答案 0 :(得分:1)
是的,您可以将IP存储在a variable:
中┌─[jamesph@ilmr] - [~/temp/ansible] - [Wed Sep 28, 12:28]
└─[$]> cat provision.yaml
- hosts: localhost
tasks:
- shell: echo 'so cool'
register: message
- hosts: localhost
roles:
- example
┌─[jamesph@ilmr] - [~/temp/ansible] - [Wed Sep 28, 12:28]
└─[$]> tree roles
roles
└── example
└── tasks
└── main.yaml
2 directories, 1 file
┌─[jamesph@ilmr] - [~/temp/ansible] - [Wed Sep 28, 12:28]
└─[$]> cat roles/example/tasks/main.yaml
- debug:
msg: "got message: {{ message }}"
┌─[jamesph@ilmr] - [~/temp/ansible] - [Wed Sep 28, 12:28]
└─[$]> ansible-playbook provision.yaml
[WARNING]: Host file not found: /etc/ansible/hosts
[WARNING]: provided hosts list is empty, only localhost is available
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [command] *****************************************************************
changed: [localhost]
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [example : debug] *********************************************************
ok: [localhost] => {
"msg": "got message: {u'changed': True, u'end': u'2016-09-28 12:28:51.493133', u'stdout': u'so cool', u'cmd': u\"echo 'so cool'\", u'start': u'2016-09-28 12:28:51.489753', u'delta': u'0:00:00.003380', u'stderr': u'', u'rc': 0, 'stdout_lines': [u'so cool'], u'warnings': []}"
}
PLAY RECAP *********************************************************************
localhost : ok=4 changed=1 unreachable=0 failed=0
AWS detailed guide提供了注册ec2
模块结果并将其用于以后任务的示例。