ansible-2.x

How to loop over this dictionary in Ansible?

老子叫甜甜 提交于 2019-11-28 21:29:11
Say I have this dictionary war_files: server1: - file1.war - file2.war server2: - file1.war - file2.war - file3.war and for now I just want to loop over each item (key), and then over each item in the key (value). I did this - name: Loop over the dictionary debug: msg="Key={{ item.key }} value={{ item.value }}" with_dict: "{{ war_files }}" And I get this. It is of course correct, but is NOT what I want. ok: [localhost] => (item={'value': [u'file1.war', u'file2.war'], 'key': u'server1'}) => { "item": { "key": "server1", "value": [ "file1.war", "file2.war" ] }, "msg": "Server=server1, WAR=[u

accessing inventory host variable in ansible playbook

好久不见. 提交于 2019-11-27 21:51:19
I am using ansible 2.1. I have the following inventory host file and a role being called by a play that needs access to the host file variable. Any thoughts on how to access it (currently getting an error): host file [test1] test-1 ansible_ssh_host=abc.def.ghi.jkl ansible_ssh_port=1212 [test2] test2-1 ansible_ssh_host=abc.def.ghi.mno ansible_ssh_port=1212 [test3] test3-1 ansible_ssh_host=abc.def.ghi.pqr ansible_ssh_port=1212 test3-2 ansible_ssh_host=abc.def.ghi.stu ansible_ssh_port=1212 [all:children] test1 test2 test3 role I have tried accessing the role in the following fashions: {{ hostvars

How to use Ansible 2.0 Python API to run a Playbook?

旧城冷巷雨未停 提交于 2019-11-27 21:33:18
I'm trying to write a python script which will call existing Ansible playbooks as it goes (because I want to loop over a list of plays while looping over a list of variables). This post explains it very well, for ansible pre-2.0: Running ansible-playbook using Python API This doc explains it very well if you're writing a new playbook in your script: http://docs.ansible.com/ansible/developing_api.html But I don't see how to call an existing playbook using Python API 2.0, and ansible.runner no longer works. Help me, Stackoverflow-Wan Kenobi. You're my only hope. The documentation is surprisingly

How to loop over this dictionary in Ansible?

眉间皱痕 提交于 2019-11-27 20:58:22
问题 Say I have this dictionary war_files: server1: - file1.war - file2.war server2: - file1.war - file2.war - file3.war and for now I just want to loop over each item (key), and then over each item in the key (value). I did this - name: Loop over the dictionary debug: msg="Key={{ item.key }} value={{ item.value }}" with_dict: "{{ war_files }}" And I get this. It is of course correct, but is NOT what I want. ok: [localhost] => (item={'value': [u'file1.war', u'file2.war'], 'key': u'server1'}) => {

Ansible extracting atributes and create new dictionary

别来无恙 提交于 2019-11-27 03:41:06
问题 I have a json object which looks as follows: [ { "id": "subnet-1", "tags": { "Name": "showcase" } }, { "id": "subnet-2", "tags": { "Name": "qa" } } ] and i would like to create a new dictionary with only subnetIds with tag name 'Name' used as key and 'id' used as value as follows: { "showcase": "subnet-1", "qa": "subnet-2", } currently i have following code which does not help: - name: Populate SubnetIds set_fact: SubnetIds: "{{ subnet_facts.subnets | map(attribute='tags.Name') | join(',') }}

How to use Ansible 2.0 Python API to run a Playbook?

倖福魔咒の 提交于 2019-11-26 23:04:03
问题 I'm trying to write a python script which will call existing Ansible playbooks as it goes (because I want to loop over a list of plays while looping over a list of variables). This post explains it very well, for ansible pre-2.0: Running ansible-playbook using Python API This doc explains it very well if you're writing a new playbook in your script: http://docs.ansible.com/ansible/developing_api.html But I don't see how to call an existing playbook using Python API 2.0, and ansible.runner no

accessing inventory host variable in ansible playbook

社会主义新天地 提交于 2019-11-26 16:31:17
问题 I am using ansible 2.1. I have the following inventory host file and a role being called by a play that needs access to the host file variable. Any thoughts on how to access it (currently getting an error): host file [test1] test-1 ansible_ssh_host=abc.def.ghi.jkl ansible_ssh_port=1212 [test2] test2-1 ansible_ssh_host=abc.def.ghi.mno ansible_ssh_port=1212 [test3] test3-1 ansible_ssh_host=abc.def.ghi.pqr ansible_ssh_port=1212 test3-2 ansible_ssh_host=abc.def.ghi.stu ansible_ssh_port=1212 [all