ansible-playbook

Ansible: how to get host specific variable value by hostname

▼魔方 西西 提交于 2019-12-11 05:52:17
问题 I'd like to insert initial values to a client's sqlite by Ansible and the values are different for every host. I created myrole/vars/main.yml: hostname1: id: id_1 value: value_1 hostname2: id: id_2 value: value_2 I want to to get it by {{ {{ inventory_hostname }}.id }} and insert the template of .sql, but it is not working. 回答1: You can achieve by modify your variable like this: clients: hostname1: id: id_1 value: value_1 hostname2: id: id_2 value: value_2 Then in your template: {{ clients

Can't run Ansible in daemon-mode

我怕爱的太早我们不能终老 提交于 2019-12-11 03:07:15
问题 Can I run Ansible to manage my hosts like a daemon? For example, I sometimes change my playbooks and I don't want to run "ansible-playbook main.yml" manually. Please, don't propose crontab. There is a specific point and I can't use crontab on production server. Thank you 回答1: What you are talking about here is called pull mode . Architectually Ansible is designed to work in push mode - you push changes to server from a control machine. If you really would like to make Ansible work in pull

ansible: accessing register variables from other plays within same playbook

 ̄綄美尐妖づ 提交于 2019-12-11 02:18:51
问题 I'm trying to access the variable called "count" from the first "play" in my playbook in the second playbook. I found some other posts here about the same issue and I thought I was following the right steps, but the code below is still failing. The Code - hosts: group1 tasks: - name: count registrations on primary node shell: psql -U widgets widgets -c 'SELECT COUNT(*) FROM location' -t register: count - debug: var=count.stdout - hosts: group2 tasks: #the line below works... # - debug: msg={{

How to get all tasks of ansible playbook limit to ansible_os_family?

北慕城南 提交于 2019-12-11 02:16:18
问题 I need get list of all tasks from ansible playbook and show them. My problem is conditions like ansible_os_family == "Debian" not executing. I see all tasks (like ansible-playbook rplaybooks/main.yml --list-task). But I want only those that will be executed. I see two ways: I will check when to current ansible_os_family. I don't know how to get it? I will find way inside python-ansible execute this conditions I created class, that allow to get playbook tasks playbook.py: import sys import os

Ansible, the field args has an invalid value [duplicate]

纵然是瞬间 提交于 2019-12-11 01:32:36
问题 This question already has an answer here : How to use Ansible's with_item with a variable? (1 answer) Closed last year . I added a role called common to my playbook.yml, and provisioning fails with the message: TASK [common : Host is present] ************************************************ ==> cd: fatal: [localhost]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: 'unicode object' has no

How do I narrow down scope when running an ansible playbook?

有些话、适合烂在心里 提交于 2019-12-11 00:48:11
问题 I have a playbook that takes a lot of time to execute, partly due to having a lot of nodes on which it has to run on (I am wasting time with ansible checking the status of all the nodes), and I need to make some changes somewhere in the middle of it. What would be the best way in which I could narrow down the scope of the playbook? I've considered isolating the required change and/or just running the modified part on a single node? 回答1: This is what tags are for. You can tag any tasks with

Ansible Expect module can't match string/regex script questions

我怕爱的太早我们不能终老 提交于 2019-12-10 23:11:31
问题 I'm trying to automate a script installation through Ansible in a Vagrant machine. I tried a lot to find a solution across the web but the documentation and the examples are very weak. That script I'm trying to install is prompting questions that I'm trying to answer programmatically with the Ansible Expect Module . Ansible Task: - name: "Running Lisk installation" become: True become_user: vagrant expect: command: bash installLisk.sh install -r {{env}} responses: 'Where do you want to

ansible playbook unable to continue as the `tar` fails due to `file change as we read`

泪湿孤枕 提交于 2019-12-10 22:34:20
问题 I am running an ansible-playbook which is doing running tar command to zip a directory. Following is the ansible task. - name: tar the old code command: tar -czf {{ansible_date_time.date}}.tar.gz /home/ubuntu/my-folder The above gives the following error. "warnings": use unarchive module rather than running tar stderr: tar: Removing leading '/' from member names tar: /home/ubuntu/my-folder/xyz.log: file change as we read it I also tried with option --ignore-failed-read but it didn't zipped

Access ansible.cfg variable in task

邮差的信 提交于 2019-12-10 21:23:33
问题 How can I refer remote_tmp (or any other) value defined in ansible.cfg in my tasks? For example, in the my_task/defaults/main.yml : file_ver: "1.5" deb_file: "{{ defaults.remote_tmp }}/deb_file_{{ file_ver }}.deb" produces an error: fatal: [x.x.x.x]: FAILED! => {"failed": true, "msg": "the field 'args' has an invalid value, which appears to include a variable that is undefined. The error was: {{ defaults.remote_tmp }}/deb_file_{{ file_ver }}.deb: 'defaults' is undefined\... } 回答1: You can't

Ansible playbook condition fails when variable has a default value

末鹿安然 提交于 2019-12-10 18:43:58
问题 Given the following playbook ( deployment.yml ): --- - name: Debug hosts: applicationservers tasks: - debug: msg="{{add_host_entries | default('false')}}" - debug: msg="{{add_host_entries | default('false') == 'true'}}" - debug: msg="Add host entries = {{add_host_entries | default('false') == 'true'}}" - include: add_host_entries.yml when: add_host_entries | default('false') == 'true' The condition to include add_host_entries.yml always fails, even if all of the above debug messages print