ansible-inventory

How do i fix the Broken pipe error during Ansible Play

淺唱寂寞╮ 提交于 2020-04-17 22:00:44
问题 I am getting this below error while running my Ansible play. It was working perfectly fine till couple of days ago and suddenly started happening for this particular host. I don't know if some configuration change happened on this server but any idea what could be wrong? The same play works fine for other environment like Prod. Command ansible-playbook -i my-inventory my-main.yml --tags=copyRepo-e my_release_version=5.0.0-4 -e target_env=preprod --ask-become-pass I am able to ssh as well

How to define group_var for multiple host in same environment

a 夏天 提交于 2020-04-16 04:49:10
问题 I am writing a Ansible playbook which copy and deploy multiple wars to different servers of same environment. For example, my preprod environment has 4 different servers and on every release I get 5 war files let's say test1.war, test2.war... test5.war. They should be deployed in this way - PreProd - server1 : test1.war, test2.war - server2 : test2.war, test5.war - server3 : test3.war, test1.war, test5.war AND so on. Now I am using group_vars to define all the variables related to preprod at

Is there a way to use a regular expression to match hosts in ansible?

拥有回忆 提交于 2020-03-03 10:46:07
问题 I am trying to match hosts using a regex pattern with ansible but it is not working as expected. My inventory is as seen below: [group1] hello1 world1 hello2 world2 [group2] hello3 And my task is: - debug: msg: "{{ item }}" with_inventory_hostnames: - ~hello* From their documentation: Using regexes in patterns You can specify a pattern as a regular expression by starting the pattern with ~: ~(web|db).*\.example\.com When I execute the task there is no output. I am a n00b with regex so could

Using --become for ansible_connection=local

你说的曾经没有我的故事 提交于 2020-02-21 15:21:13
问题 With a personal user account (userx) I run the ansible playbook on all my specified hosts. In ansible.cfg the remote user (which can become root) to be used is: remote_user = ansible For the remote hosts this all works fine. It connects as the user Ansible, and executes all tasks as wished for, also changing information (like /etc/ssh/sshd_config ) which requires root rights. But now I also want to execute the playbook on the Ansible host itself. I put the following in my inventory file:

Using --become for ansible_connection=local

痞子三分冷 提交于 2020-02-21 15:12:22
问题 With a personal user account (userx) I run the ansible playbook on all my specified hosts. In ansible.cfg the remote user (which can become root) to be used is: remote_user = ansible For the remote hosts this all works fine. It connects as the user Ansible, and executes all tasks as wished for, also changing information (like /etc/ssh/sshd_config ) which requires root rights. But now I also want to execute the playbook on the Ansible host itself. I put the following in my inventory file:

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

How do you get group name of the executing role in ansible [duplicate]

帅比萌擦擦* 提交于 2020-01-24 05:50:09
问题 This question already has answers here : How to list groups that host is member of? (3 answers) Closed 2 years ago . I have a use case where I need to create a directory in all hosts in a group whose name will be the name of the group. Eg : I create a dynamic inventory file with output of the form : { "db": ["host1", "host2", "host3"], "logs": ["host2"], "misc": ["host4"] } I need to create a directory by the name db in every host of the group db and directory named log in every host of the

Is it possible to write Ansible hosts/inventory files in YAML?

人走茶凉 提交于 2020-01-09 03:18:04
问题 In the best practices page, there is an example that uses hosts.yml for hosts files: In the docs, however, I can only find the INI syntax for writing hosts files. What is the syntax for the inventory files in YAML? 回答1: Yes. It's been deprecated in version 0.6 in 2012 and reintroduced in a commit first included in version 2.1 in 2016. The example file on GitHub contains the guidelines and examples: Comments begin with the '#' character Blank lines are ignored Top level entries are assumed to

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