ansible-2.x

How can I get a list of hosts from an Ansible inventory file?

白昼怎懂夜的黑 提交于 2020-02-19 09:39:40
问题 Is there a way to use the Ansible Python API to get a list of hosts from a given inventory file / group combination? For example, our inventory files are split up by service type: [dev:children] dev_a dev_b [dev_a] my.host.int.abc.com [dev_b] my.host.int.xyz.com [prod:children] prod_a prod_b [prod_a] my.host.abc.com [prod_b] my.host.xyz.com Can I use ansible.inventory in some way to pass in a specific inventory file, and the group I want to act on, and have it return a list of hosts that

Set different ORACLE_HOME and PATH environment variable using Ansible

余生颓废 提交于 2020-02-06 08:23:30
问题 Im currently querying multiple databases and capturing the results of the query The way Im doing it is, Im writing a task which copies a shell script, something like below #!/bin/bash source $HOME/bin/gsd_xenv $1 &> /dev/null sqlplus -s <<EOF / as sysdba set heading off select d.name||','||i.instance_name||','||i.host_name||';' from v\$database d,v\$instance i; EOF In the playbook, Im writing the task as below: - name: List Query [Host and DB] shell: "/tmp/sqlscript/sql_select.sh {{item}} >>

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

import an variable file to another in ansible

假装没事ソ 提交于 2020-01-24 20:20:13
问题 I am new to ansible. I have 2 variable files one is global and another is environment specific. Here is the global one in global/group_var/all.yaml folder: rel: deployment: webui: dockerName: "rel" dockerTag: "Dev_{{ travis.build_number }}" And the specific one is in develop/group_var/all.yaml folder docker: registery: "xxxx" is there any way I can import global/group_var/all.yaml to develop/group_var/all.yaml import global/group_var/all.yaml docker: registery: "xxxx" so develop/group_var/all

Ansible - pip not found

痴心易碎 提交于 2020-01-23 08:34:27
问题 I am getting this error: TASK [pip] ********************************************************************* failed: [default] (item=urllib3) => {"changed": false, "item": "urllib3", "msg": "Unable to find any of pip2, pip to use. pip needs to be installed."} Upon a suggestion I run following command: ansible default -a "which pip" I get an error: default | FAILED | rc=1 >> non-zero return code So I guess that means no pip installed. I tried installing pip using: ansible default -a "easy_install

Calling an Ansible Module from another Ansible Module?

五迷三道 提交于 2020-01-15 05:32:49
问题 Question Is it possible to call an Ansible module from another Ansible module programmatically? Context I have been working with Cisco UCS via Python (ucsmsdk) and Ansible to create a means of automating service profile templates (SPTs from now on). I have created apis and modules conforming to the standards set in the respective Git repos. While I am able to create these SPTs with an Ansible playbook, it requires a lot of reused properties to create each individual item and follow their long

Calling an Ansible Module from another Ansible Module?

空扰寡人 提交于 2020-01-15 05:32:01
问题 Question Is it possible to call an Ansible module from another Ansible module programmatically? Context I have been working with Cisco UCS via Python (ucsmsdk) and Ansible to create a means of automating service profile templates (SPTs from now on). I have created apis and modules conforming to the standards set in the respective Git repos. While I am able to create these SPTs with an Ansible playbook, it requires a lot of reused properties to create each individual item and follow their long

Ansible template adds 'u' to array in template

不打扰是莪最后的温柔 提交于 2020-01-10 14:09:47
问题 I have the following vars inside of my ansible playbook I got the following structure domains: - { main: 'local1.com', sans: ['test.local1.com', 'test2.local.com'] } - { main: 'local3.com' } - { main: 'local4.com' } And have the following inside of the my conf.j2 {% for domain in domains %} [[acme.domains]] {% for key, value in domain.iteritems() %} {% if value is string %} {{ key }} = "{{ value }}" {% else %} {{ key }} = {{ value }} {% endif %} {% endfor %} {% endfor %} Now when I go in the

Change variable in Ansible template based on group with children?

时光总嘲笑我的痴心妄想 提交于 2020-01-07 05:23:48
问题 I found Change variable in Ansible template based on group. However how do I extend the answer in groups with children? If I extend the group vars file in the link above to [host0] host0.my-network.com [host1] host1.my-network.com [es-masters:children] host0 host1 How can I extend the above post's answer (shown below) to make it work with the group vars file above? Simply putting the FQDN in the jinja2 statement does not work. {% if ansible_fqdn in groups['es-masters'] %} node_master=true {%

Change variable in Ansible template based on group with children?

纵然是瞬间 提交于 2020-01-07 05:23:04
问题 I found Change variable in Ansible template based on group. However how do I extend the answer in groups with children? If I extend the group vars file in the link above to [host0] host0.my-network.com [host1] host1.my-network.com [es-masters:children] host0 host1 How can I extend the above post's answer (shown below) to make it work with the group vars file above? Simply putting the FQDN in the jinja2 statement does not work. {% if ansible_fqdn in groups['es-masters'] %} node_master=true {%