ansible

“skipping: no hosts matched” issue with Vagrant and Ansible

人盡茶涼 提交于 2019-12-31 17:51:32
问题 I have installed Vagrant, VirtualBox and Ansible and trying to run provision over one host but it always returns "skipping: no hosts matched" The head of my playbook file looks like this: --- - hosts: webservers user: vagrant sudo: yes and my /etc/ansible/hosts file looks like this: [webservers] webserver1 I tried putting the IP address there but had the same result. I have added my ssh key to the server and added webserver1 host to both .ssh/config and /etc/hosts . I can ssh vagrant

“skipping: no hosts matched” issue with Vagrant and Ansible

試著忘記壹切 提交于 2019-12-31 17:51:15
问题 I have installed Vagrant, VirtualBox and Ansible and trying to run provision over one host but it always returns "skipping: no hosts matched" The head of my playbook file looks like this: --- - hosts: webservers user: vagrant sudo: yes and my /etc/ansible/hosts file looks like this: [webservers] webserver1 I tried putting the IP address there but had the same result. I have added my ssh key to the server and added webserver1 host to both .ssh/config and /etc/hosts . I can ssh vagrant

Ansible: Set variable only if undefined

喜欢而已 提交于 2019-12-31 12:56:10
问题 I would like to set an ansible variable to some default value but only if the variable is undefined. Otherwise I would like to keep it unchanged. I tried these two approaches and both of them produce recursive loop: namespace: "{{namespace|default(default_namespace)}}" namespace: "{% if namespace is defined %}{{namespace}}{% else %}{{default_namespace}}{% endif %}" 回答1: It seems like you are taking a wrong approach. Take a look at the Ansible documentation concerning variable precedence. It

Ansible - using with_items and when conditional to

元气小坏坏 提交于 2019-12-31 09:10:48
问题 I have a bunch of servers that have four physical drives on them (/dev/sda, sdb, sdc, and sdd). sda has the OS installed on it. I need to format each drive except sda. I need to check if each drive has data on it. If it does, then I shouldn't format it. # This will get all physical disks (sda, sdb, sdc, etc) and assign them to disk_var - name: Get disks set_fact: disk_var="{{hostvars[inventory_hostname]["ansible_devices"].keys()|list}}" - name: Check if the disk is partitioned and also ignore

How to continue execution on failed task after fixing error in playbook?

本秂侑毒 提交于 2019-12-31 08:33:22
问题 When writing and debugging Ansible playbooks, typical workflow is as follows: ansible-playbook ./main.yaml Playbook fails on some task Fix this task and repeat line 1, waiting for all previous tasks to execute again. Which takes a lot of time Ideally, i'd like to resume execution on failed task, having inventory and all facts collected by previous tasks. Is it even possible? How to make playbook writing/debugging faster? 回答1: Take a look at http://docs.ansible.com/playbooks_startnstep.html.

Ansible loop related issues

。_饼干妹妹 提交于 2019-12-31 05:36:11
问题 I have a playbook which has multiple roles and serial setup so that fist it's running on one machine then on the rest of them. In one of the roles I have the following tasks: - name: getting dbnodes IP addresses local_action: shell echo "{% for host in groups['dbnodes'] %}{{ hostvars[host]['ansible_eth0']['ipv4']['address'] }},{% endfor %}" run_once: true register: IPS Basically what I want to do is to gather the IP addresses of all the hosts and register it with IPS for further usage. But

Ansible with_subelements nested levels

眉间皱痕 提交于 2019-12-31 04:17:07
问题 I'm trying to iterate through nested loops, much like this question: Ansible with_subelements I need to go an extra level deep though. The comment there (dated January 2017) states that additional levels of nesting are unsupported. Is this still the case? If not, how can I reference deeper levels? My data: dns: - name: Something prefix: st zones: - zone: something.com records: - record: testing.something.com type: TXT value: '"somethingtest"' ttl: 60 - name: Devthing prefix: dt zones: - zone:

Ansible regex escape dollar character

丶灬走出姿态 提交于 2019-12-31 04:13:26
问题 I'm trying to modify URL value in config file using Ansible $CONSOLE_URI = "http://172.18.18.103/controller/"; I'm using lineinfile module, but it doesn't work, I have tried to escape $ with double back slashes, but it hasn't worked either. - lineinfile: dest=/etc/log.conf regexp='^\\$CONSOLE_URI' line='$CONSOLE_URI=http://google.com'; 回答1: I think your regex is correct. I just tested this and the line written to the file actually has the quotes inside. This is the content of /etc/log.conf :

Ansible: how to solve “sudo: a password is required” error? [duplicate]

烂漫一生 提交于 2019-12-31 01:41:05
问题 This question already has an answer here : How can a user with SSH keys authentication have sudo powers in Ansible? [duplicate] (1 answer) Closed last year . I have 9 servers and i am trying to install a package using ansible, i am able to ssh into 5 of the servers using a password and other 4 does not ask any password while ssh'ng into them. However i have copied id_rsa.pub key to all the 9 servers. Now the ansible script is working fine for 5 server but w remaining 4 i am getting the

Ansible way to stop a service only if it needs to be upgraded

∥☆過路亽.° 提交于 2019-12-31 00:45:15
问题 In an ansible playbook I want to stop MariaDB if an upgrade is needed (restart from the RPM package does not always work in my situation). I'm quite new to ansible. I came up with this: - name: "Check if MariaDB needs to be upgraded" shell: "yum check-update MariaDB-server|grep MariaDB|wc -l" register: needs_update - name: "Stop mysql service" service: name: mysql state: stopped when: needs_update.stdout == "1" Is there a better way to do this then by executing a shell command? When running