ansible-role

Ansible: Can't set variable for sequential execution

走远了吗. 提交于 2019-12-24 00:37:58
问题 I'm trying to build a playbook with rolling update use case (Sequential Execution) with the serial element. Since I have to use the serial value in multiple places in the playbook, I wanted to use it as a variable which can be used to define somewhere as a group variable. Inventory file [all] webserver1 ansible_host=10.1.1.1 ansible_user=root webserver2 ansible_host=10.1.1.2 ansible_user=root webserver3 ansible_host=10.1.1.3 ansible_user=root dbserver1 ansible_host=10.1.2.1 ansible_user=root

Ansible not detecting Role default variables in its handler

浪子不回头ぞ 提交于 2019-12-20 02:11:03
问题 Does ansible pass Role Default variables to the Handlers within the same Role? Here's a minimal excerpt of the playbook that has the issue: Role hierarchy - playbook.yml - roles/ - gunicorn/ - defaults/ - main.yml - handlers/ - main.yml - code-checkout/ - tasks/ - main.yml Here's the file contents gunicorn/defaults/main.yml --- gu_log: "/tmp/gunicorn.log" gunicorn/handlers/main.yml --- - name: Clear Gunicorn Log shell: rm {{ gu_log }} finalize/tasks/main.yml --- - name: Test Handlers shell:

Where to place requirements.yml for Ansible and use it to resolve dependencies?

情到浓时终转凉″ 提交于 2019-12-18 04:14:10
问题 I am new to ansible and was exploring dependent roles. documentation link What I did not come across the documentation was- where to place the requirements.yml file. For instance, if my site.yml looks like this: --- - name: prepare system hosts: all roles: - role1 And, lets say role1 depends on role2 and role3 role2 depends on role4 and role5 Typically, ansible-galaxy have the following structure: └── test-role ├── defaults │ └── main.yml ├── files ├── handlers │ └── main.yml ├── meta │ └──

Set Ansible role defaults conditionally

烂漫一生 提交于 2019-12-13 22:05:57
问题 Pseudocode: If env is de, set variable name to hello else if env is prod, set variable name to bye. I tried https://serverfault.com/questions/715769/ansible-change-default-value-according-to-a-condition - name: setting variable set_fact: name="hello" when: "{{ env }}" == "de" - name: setting variable set_fact: name="bye" when: "{{ env }}" == "prod" ERROR! The default/main.yml file for role 'trial' must contain a dictionary of variables 回答1: As per my requirement, it needs to be done in role

Define Ansible variable in a role with OS specific default which can be easily overridden

こ雲淡風輕ζ 提交于 2019-12-12 18:04:31
问题 I'm writing an Ansible role that is usable on different Linux OS families and has a different default value for variables per OS family. At first, I thought this would be easy to set up using an include vars task in the role, such as: - name: Gather OS family variables include_vars: "{{ ansible_os_family|lower }}.yml" with my_role_variable: "Here is the default for Enterprise Linux" in myrole/vars/redhat.yml my_role_variable: "Here is the default for Debian Linux" in myrole/vars/debian.yml

What's the difference between roles and tasks (and tags) in Ansible?

*爱你&永不变心* 提交于 2019-12-12 16:25:34
问题 I'm finding myself getting confused between roles and tasks all the time. I get that tags are a way to tag individual items, but I'm confused how I'd use them. Let's say I had to do the following Users Create a user named "deploy" Add ssh key for "deploy" user Git Install git Clone some git repo Would "Users" and "Git" be my two main roles in the top level YML file? Would each sub-item (e.g "Install Git") be a task? Would I tag each sub-task with a tag? Or do I tag roles with a tag? Just

How to always run some ansible roles after previous failures?

坚强是说给别人听的谎言 提交于 2019-12-12 14:24:23
问题 I have a set of playbooks that do look like - name: Run test hosts: tester roles: - { role: setup_repos } - { role: setup_environment } - { role: install_packages } - { role: run_tests } - { role: collect_logs } The current problem is that all over the first 4 roles we have ignore_errors: true which is not a good practice as it makes very hard to read the output and to debug. The only reason why ignore_errors was abused was because we wanted to be able to perform the collect_logs at the end,

How to automatically install Ansible Galaxy roles, using Vagrant?

给你一囗甜甜゛ 提交于 2019-12-12 08:34:27
问题 Using one playbook only, then it's not possible to have Ansible automagically install the dependent roles. At least according to this SO thread. But, I have the added "advantage" of using Vagrant and Vagrant's Ansible local provisioner . Any tricks I may apply? 回答1: Update 2018-11-22! Given the evolution of software, I can not guarantee that all of the "old stuff/answer" below is still legit and won't set your machine on fire lol. I do, however, maintain a Vagrantfile on GitHub that does

Conditional role inclusion fails in Ansible

一世执手 提交于 2019-12-11 08:25:25
问题 I want to run an Ansible role conditionally, i.e. only when some binary does NOT exist (which for me implies absence of some particular app installation). Something like the pattern used here. Using the following code in my playbook: - hosts: my_host tasks: - name: check app existence command: /opt/my_app/somebinary register: myapp_exists ignore_errors: yes roles: - { role: myconditional_role, when: myapp_exists|failed } - another_role_to_be_included_either_way Here is the output: PLAY ******

Ansible - multiple roles

与世无争的帅哥 提交于 2019-12-11 05:25:23
问题 I am trying to run multiple roles using with_items command, however I am getting error: "ERROR! 'item' is undefined" role.yml : --- - hosts: '{{ host }}' become: yes roles: - role: "{{item}}" with_items: "{{ roles }}" Here is my command: ansible-playbook -i ./inventory/Dev ./playbooks/role.yml --extra-vars='{"host": "db", "roles": ["mysql", "apache"]}' 回答1: You cannot do it this way. with_ loops are not valid for roles. If anything, you need to provide a list of roles to the roles: directive,