ansible-role

Ansible run always role

♀尐吖头ヾ 提交于 2019-12-10 10:28:16
问题 Is there any way to always run a role? I am creating lock file before starting any deployment to prevent parallel deployment. In case of any failure/success I want to delete the lock file. - { role: lock-deployment, tags: always } - { role: fetch-artifactory, tags: always } - { role: unlock-deployment, tags: always } I want to run unlock-deployment role irrespective of failure/success. 回答1: problem is I don't want to do block, rescue for every task. I just want to delete lock file in case of

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

放肆的年华 提交于 2019-12-04 07:38:47
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 │ └── main.yml ├── README.md ├── tasks │ └── main.yml ├── templates ├── tests │ ├── inventory │ └── test.yml └

How to automatically install Ansible Galaxy roles, using Vagrant?

陌路散爱 提交于 2019-12-04 04:48:07
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? 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 install Ansible Galaxy roles automatically and this guy should essentially be regarded as the only one and holy

How to split an ansible role's `defaults/main.yml` file into multiple files?

给你一囗甜甜゛ 提交于 2019-12-04 02:59:20
In some ansible roles (e.g. roles/my-role/ ) I've got quite some big default variables files ( defaults/main.yml ). I'd like to split the main.yml into several smaller files. Is it possible to do that? I've tried creating the files defaults/1.yml and defaults/2.yml , but they aren't loaded by ansible. The feature I'm describing below has been available since Ansible 2.6, but got a bugfix in v2.6.2 and another (minor) one in v2.7. To see a solution for older versions, see Paul's answer. defaults/main/ Instead of creating defaults/main.yml , create a directory — defaults/main/ — and place all

Ansible not detecting Role default variables in its handler

假装没事ソ 提交于 2019-12-01 23:26:38
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: ls notify: - Restart Gunicorn playbook.yml --- - name: Deploy hosts: webservers tasks: - include: roles

Ansible: Can I execute role from command line?

风流意气都作罢 提交于 2019-11-30 10:32:37
问题 Suppose I have a role called "apache" Now I want to execute that role on host 192.168.0.10 from the command line from Ansible host ansible-playbook -i "192.168.0.10" --role "path to role" Is there a way to do that? 回答1: I am not aware of this feature, but you can use tags to just run one role from your playbook. roles: - {role: 'mysql', tags: 'mysql'} - {role: 'apache', tags: 'apache'} ansible-playbook webserver.yml --tags "apache" 回答2: With ansible 2.7 you can do this: $ cd /path/to/ansible/

How to split an ansible role's `defaults/main.yml` file into multiple files?

允我心安 提交于 2019-11-30 02:45:59
问题 In some ansible roles (e.g. roles/my-role/ ) I've got quite some big default variables files ( defaults/main.yml ). I'd like to split the main.yml into several smaller files. Is it possible to do that? I've tried creating the files defaults/1.yml and defaults/2.yml , but they aren't loaded by ansible. 回答1: The feature I'm describing below has been available since Ansible 2.6, but got a bugfix in v2.6.2 and another (minor) one in v2.7. To see a solution for older versions, see Paul's answer.

Ansible: Can I execute role from command line?

ⅰ亾dé卋堺 提交于 2019-11-29 22:01:02
Suppose I have a role called "apache" Now I want to execute that role on host 192.168.0.10 from the command line from Ansible host ansible-playbook -i "192.168.0.10" --role "path to role" Is there a way to do that? I am not aware of this feature, but you can use tags to just run one role from your playbook. roles: - {role: 'mysql', tags: 'mysql'} - {role: 'apache', tags: 'apache'} ansible-playbook webserver.yml --tags "apache" With ansible 2.7 you can do this: $ cd /path/to/ansible/ $ ansible localhost -m include_role -a name=<role_name> localhost | SUCCESS => { "changed": false, "include