ansible

how to set different python interpreters for local and remote hosts

守給你的承諾、 提交于 2021-01-28 05:09:41
问题 Use-Case: Playbook 1 when we first connect to a remote host/s, the remote host will already have some python version installed - the auto-discovery feature will find it now we install ansible-docker on the remote host from this time on: the ansible-docker docs suggest to use ansible_python_interpreter=/usr/bin/env python-docker Playbook 2 We connect to the same host/s again, but now we must use the /usr/bin/env python-docker python interpreter What is the best way to do this? Currently we set

Write data with a PUT request with Ansible URI module

坚强是说给别人听的谎言 提交于 2021-01-28 04:53:41
问题 I'm just trying to translate this cURL call to ansible playbook. cURL call: curl -X PUT -d "value={aa}" "http://172.31.64.174:2379/v2/keys/coreos.com/network/config" Ansible playbook: - uri: url: "http://172.31.64.174:2379/v2/keys/coreos.com/network/config" method: PUT body: "value={aa}" I tried this one but server receive the PUT petition but value is not changed. This is the verbose output from the cURL procedure: * Trying 172.31.64.174... * Connected to 172.31.64.174 (172.31.64.174) port

Ansible K8s module: Failed to import the required Python library (openshift) on Python /usr/bin/python3

情到浓时终转凉″ 提交于 2021-01-28 03:10:56
问题 The env Ansible 2.9.6 (python3) Tried to run a simple playbook - hosts: master gather_facts: no become: yes tasks: - name: create name space k8s: name: testing api_version: v1 kind: Namespace state: present Getting following error The full traceback is: Traceback (most recent call last): File "/tmp/ansible_k8s_payload_u121g92v/ansible_k8s_payload.zip/ansible/module_utils/k8s/common.py", line 33, in <module> import kubernetes ModuleNotFoundError: No module named 'kubernetes' fatal: [192.168.20

Ansible : filter elements containing string with JMESPath

巧了我就是萌 提交于 2021-01-28 02:11:13
问题 I want to get a list of addresses of a defined interface type. I found some info here. Here is my playbook: - name: Test JMESPath hosts: localhost gather_facts: no vars: interfaces: - name: em0 address: 10.127.37.89/29 - name: bge0 address: 10.112.171.81/28 - name: bge1 address: 10.112.171.65/28 - name: bge2 address: 10.112.171.97/28 tasks: - name: JMESPath query set_fact: result: "{{ interfaces | json_query(query) }}" vars: query: "[?name.contains(@, 'bge')].address" - debug: var: result I'd

Specifying multiple default groups as hosts in an Ansible playbook

情到浓时终转凉″ 提交于 2021-01-28 01:50:55
问题 I'm looking for a way to specify multiple default groups as hosts in an Ansible playbook. I've been using this method: - name: Do things on hosts hosts: "{{ specific_hosts | default('development') }}" tasks: # do things on hosts However I'm trying to avoid specifying hosts manually (it is error-prone), and the default hosts are inadequate if I want to run the same tasks against multiple groups of servers (for instance, development and QA). I don't know if this is possible in a playbook: -

Ansible - when conditional not working for vars_prompt at playbook level

人走茶凉 提交于 2021-01-27 19:33:38
问题 ansible 2.1.2.0 I have a situation here for which I'm trying to check with you all to see if the solution is even possible with Ansible vars_prompt feature and when conditional. Ansible has this feature called: vars_prompt and I want to club this with the when conditional ( when: ... which we generally use in tasks at task or playbook level actions) PS: My question is different than this post : Ansible to Conditionally Prompt for a Variable? i.e. my vars: variables are not dependent upon any

Issue using Ansible's inventory plugin for AWS EC2

最后都变了- 提交于 2021-01-27 19:19:18
问题 I'm trying to use the aws_ec2 inventory plugin for ansible. As I understand this is supposed to be the recommended method over the ec2.py inventory script. I got that gold nugget of information from ansible's own blog post and some random articles that mention it in the passing. However, as a novice to ansible, I find the documentation lacking. 3 problems I'm wandering about are: A good way to pass secrets to the inventory definition file (I called it hosts.aws_ec2.yml ). Jinja2 style of: aws

Ansible append dict results for all hosts

假装没事ソ 提交于 2021-01-27 18:10:28
问题 I am attempting to use Ansible to send a command to several hosts that returns a dict. I then want to append the the dict results of each host to accumulate the results of all the hosts. Finally, I want to print the dict of accumulated results for later processing or to write to a file. It appears I am failing to combine the dicts due to results showing as string. Is there a way to remedy this? Also, is there a more Ansible efficient way to accomplish this? Example Playbook: --- - hosts:

Issue using Ansible's inventory plugin for AWS EC2

江枫思渺然 提交于 2021-01-27 18:01:02
问题 I'm trying to use the aws_ec2 inventory plugin for ansible. As I understand this is supposed to be the recommended method over the ec2.py inventory script. I got that gold nugget of information from ansible's own blog post and some random articles that mention it in the passing. However, as a novice to ansible, I find the documentation lacking. 3 problems I'm wandering about are: A good way to pass secrets to the inventory definition file (I called it hosts.aws_ec2.yml ). Jinja2 style of: aws

Debug statement in Ansible Playbook behaves differently than in Ansible Role

冷暖自知 提交于 2021-01-27 17:45:04
问题 I cannot seem to get an Ansible debug statement in a loop to display the individual item values when running the debug statement in a role. For comparison, given this playbook named ./test.yaml: - hosts: localhost tasks: - name: test debug: var: item loop: - 1 - 2 This command: ansible-playbook test.yaml Produces this result: PLAY [localhost] *****... TASK [test] ****... ok: [localhost] => (item=1) => { "item": 1 } ok: [localhost] => (item=2) => { "item": 2 } But given this file: ./roles