ansible-facts

Ansible: get current target host's IP address

夙愿已清 提交于 2020-05-09 17:44:48
问题 How do you get the current host's IP address in a role? I know you can get the list of groups the host is a member of and the hostname of the host but I am unable to find a solution to getting the IP address. You can get the hostname by using {{inventory_hostname}} and the group by using {{group_names}} I have tried things like {{ hostvars[{{ inventory_hostname }}]['ansible_ssh_host'] }} and ip="{{ hostvars.{{ inventory_hostname }}.ansible_ssh_host }}" 回答1: A list of all addresses is stored

ansible multiple with_items and loop on all hosts in inventory group

爱⌒轻易说出口 提交于 2020-01-25 09:40:28
问题 Team, I have a situation where I need to execute multiple commands on multiple hosts. for singular host case am fine with below but how to iterate the same over multiple hosts? - name: "SMI Tests for ECC singlebit and double bit codes " command: "smi --xml-format --query | grep retired_count | grep -v 0" ignore_errors: no register: _smi_ecc_result failed_when: _smi_ecc_result.rc == 0 delegate_to: "{{ item }}" with_items: "{{ groups['kube-gpu-node'] }}" Now, i have more commands to execute how

Is it possible to read set_fact of a dynamically constructed host in different Ansible play

十年热恋 提交于 2020-01-16 09:10:03
问题 I'm aware of how to read set_fact across different plays. I have also read about issues regarding set_fact in another play. However, I did not come across any example where the set_fact used under a Play having dynamically constructed host using add_host and it now needs to be read by another play having hosts: localhost I was expecting host_vars to help me but the below playbook test shows that host_vars also does not help and I get a variable undefined error. You can run the playbook and

How to use return values of one task in another task for a different host in ansible

岁酱吖の 提交于 2020-01-06 08:16:26
问题 I was trying to setup mysql master slave replication with ansible for a hostgroup consisting of 2 mysql hosts. Here is my scenario: I run one task in the 1st host and skips the 2nd host, so the 1st task (i.e master replication status) returns some values like Position, File etc. Then, I run another task in 2nd host (skips the 1st hosts), This task uses the return values of the 1st task like master.Position, master.File etc. Now, when I run the playbook, the variables of the 1st task does not

How to use return values of one task in another task for a different host in ansible

浪尽此生 提交于 2020-01-06 08:14:25
问题 I was trying to setup mysql master slave replication with ansible for a hostgroup consisting of 2 mysql hosts. Here is my scenario: I run one task in the 1st host and skips the 2nd host, so the 1st task (i.e master replication status) returns some values like Position, File etc. Then, I run another task in 2nd host (skips the 1st hosts), This task uses the return values of the 1st task like master.Position, master.File etc. Now, when I run the playbook, the variables of the 1st task does not

how to set ansible conditinal search

自作多情 提交于 2020-01-06 08:03:21
问题 I am trying to extract few values from a task out put. please see my playbook sample - name: Iterate JSON set_fact: app_item: "{{ item.name }}" when: "{{ result.results|json_query('[].\"scope member\"[?\"vdom\"==`\"vdom-shop\"`].vdom')|flatten|first }} == vdom-shop" with_items: "{{ result.results }}" please see the json output from the previous task { "msg": { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "failed": false, "msg": "Custom Query

Ansible read multiple variables with same name from vars_file

岁酱吖の 提交于 2020-01-05 13:01:11
问题 In my ~/ip_vars_file , I have ip : 10.20.30 ip : 10.20.31 ip : 10.20.32 This is created with lineinfile, lineinfile: line="ip{{':'}} {{item.public_ip}}" dest="{{ansible_env.HOME}}/ip_vars_file}}" with_items: servers.tagged_instances #servers is registered in previous task I am unable to read all three ips as with_items. I get only the last IP in my playbook. --- - hosts: localhost tasks: - name: print ips debug: var: item with_items: "{{ ip }}" vars_files: - ~/ip_vars_file The output I am

Ansible read multiple variables with same name from vars_file

不想你离开。 提交于 2020-01-05 13:00:30
问题 In my ~/ip_vars_file , I have ip : 10.20.30 ip : 10.20.31 ip : 10.20.32 This is created with lineinfile, lineinfile: line="ip{{':'}} {{item.public_ip}}" dest="{{ansible_env.HOME}}/ip_vars_file}}" with_items: servers.tagged_instances #servers is registered in previous task I am unable to read all three ips as with_items. I get only the last IP in my playbook. --- - hosts: localhost tasks: - name: print ips debug: var: item with_items: "{{ ip }}" vars_files: - ~/ip_vars_file The output I am