ansible

Ansible/Jinja: condition with an undefined statement

岁酱吖の 提交于 2020-01-03 04:09:10
问题 I need to iterate over all hosts and generate config file for hosts that are not contained in group somegroup : {% for host in groups.all if host not in groups['somegroup'] %} But if somegroup does not exist, it fails (argument of type 'StrictUndefined' is not iterable). How do I write this correctly to avoid two different for cycles: {% if groups['somegroup'] is defined %} {% for host in groups.all if host not in groups['somegroup'] %} ... {% endfor %} {% else %} {% for host in groups.all %}

Running a task on a single host always with Ansible?

◇◆丶佛笑我妖孽 提交于 2020-01-03 03:12:07
问题 I am writing a task to download a database dump from a specific location. It will always be run on the same host. So I am including the task as follows in the main playbook: tasks: include: tasks/dl-db.yml The content of the task is: --- - name: Fetch the Database fetch: src=/home/ubuntu/mydb.sql.gz dest=/tmp/mydb.sql.bz fail_on_missing=yes But I want it to fetch from a single specific host not all hosts. Is a task the right approach for this? 回答1: If all you need to happen is that it's only

Ansible, Juniper CLI commands. Timeout Error?

守給你的承諾、 提交于 2020-01-02 09:52:28
问题 I am trying to transfer an automation script I made in Python, to ansible (company request), and I have NEVER worked with ansible before. I have tried the "wait_for:", but I have not gotten that to work either. In the script, I could set dev.timeout=None or whatever I needed. I am finding it hard to figure out where I can do this in ansible. I have tried setting the timeout in the "ansible.cfg" file. But that doesnt work. I can do simple commands, like: cli="show version", or cli="show system

Using {{ and }} in ansible shell command

淺唱寂寞╮ 提交于 2020-01-02 08:44:10
问题 I have this in my playbook: - name: Get facts about containers shell: "docker ps -f name=jenkins --format {%raw%}{{.Names}}{% endraw %}" register: container Note, that I inserted the {%raw%} and {%endraw%} so that ansible does not evaulate the '{{'. If I run this, I get this error: fatal: [localhost]: FAILED! => {"failed": true, "msg": "{u'cmd': u'docker ps -f name=jenkins --format {{.Names}}', u'end': u'2017-01-19 10:04:27.491648', u'stdout': u'ecs-sde-abn-17-jenkins-ec8eccee8c9eb8e38f01', u

Multi-machine ansible setup with vagrant on windows

我的未来我决定 提交于 2020-01-02 07:12:19
问题 Purpose I want ansible to provision virtual box vm's on my windows 8 machine [via Vagrant]. Everything needs to run locally and since Ansible doesn't run on Windows, I bootstrap a debian vm with ansible as the control machine. This code served as an example. After struggling with the system I got it somewhat working, but not completely (although ansible doesn't tell me). Question What configuration is required for a multi-machine setup using ansible [in a vm], vagrant and virtualbox [on

Execution flow - How ansible play works?

荒凉一梦 提交于 2020-01-02 06:55:11
问题 In the below machine scenario: Am trying to understand this point in documentation: "By default, Ansible runs each task on all hosts affected by a play before starting the next task on any host, using 5 forks." Say, task1 is remote execution type(not local execution type) If play1 needs to run task1 on all 4 hosts(above), then Does ansible execute task1 on host2 only after executing ( task1 on host1 and retrieve the result of execution)? How are 5 forks utilised? Note: Every task execution

Ansible - with_dict: dictionary - How to use variables defined in each dictionary which depends upon others

风格不统一 提交于 2020-01-02 04:05:36
问题 Environment is: Ansible 1.9.2, CentOS 6.5 I have created a role to download JAVA (.tar.gz) artifact files for 3 different JAVA versions from Artifactory. I'm trying to use Ansible's with_dict feature (instead of using with_items). Created the following files: $ cat roles/java/defaults/main.yml --- java_versions: java7_60: version: 1.7.60 group_path: com/oracle/jdk classifier: linux-x64 ext: tar.gz dist_file: "jdk-{{ version }}-{{ classifier }}-{{ ext }}" # dist_file: "jdk-{{item.value.version

Ansible: How to declare global variable within playbook?

空扰寡人 提交于 2020-01-02 03:24:19
问题 How can I declare global variable within Ansible playbook. I have searched in google and found the below solution, but its not working as expected. - hosts: all vars: prod-servers: - x.x.x.x - x.x.x.x - hosts: "{{prod-servers}}" tasks: - name: ping action: ping When I'm trying the above code, it says variable prod-servers is undefined. 回答1: You cannot define a variable accessible on a playbook level (global variable) from within a play. Variable Scopes Ansible has 3 main scopes: Global: this

ansible reboot 2.1.1.0 fails

自闭症网瘾萝莉.ら 提交于 2020-01-02 02:38:49
问题 I've been trying to create a really simple Ansible playbook that will reboot a server and wait for it to come back. I've had one in the past on Ansible 1.9 that worked, but i've recently upgraded to 2.1.1.0 and it fails. The host i'm rebooting is called idm and has an IP of 192.168.200.23. the playbook is being run from my host 192.168.200.1 with the command $ ansible-playbook reboot.yml -vvvv This is the playbook i'm using --- - hosts: idm tasks: - name: Restart server become: yes shell:

How to compare kernel (or other) version numbers in Ansible

最后都变了- 提交于 2020-01-02 00:56:06
问题 For a role I'm developing I need to verify that the kernel version is greater than a particular version. I've found the ansible_kernel value, but is there an easy way to compare this to other versions? I thought I might manually explode the version string on the '.'s & compare the numbers, but I can't even find a friendly filter to explode the version string out, so I'm at a loss. Thanks in advance. T 回答1: There is a test for it: {{ ansible_distribution_version | version_compare('12.04', '>='