ansible-playbook

How can Ansible loop over a sequence of tasks?

可紊 提交于 2019-12-06 03:02:46
问题 How can an Ansible playbook loop over a sequence of tasks? I wish to implement a polling loop that executes a task sequence until the task is successful. When it fails, an exception handler will attempt to fix the condition and then the loop will repeat the task sequence. Consider the following imaginary example: - action: - block: - debug: msg='i execute normally' - command: /bin/foo rescue: - debug: msg='I caught an error' - command: /bin/fixfoo always: - debug: msg="this always executes"

Ansible output formatting options

安稳与你 提交于 2019-12-06 01:33:15
Is there an option to format ansible output with the use of ansible (not any other scripts)? For instance name: Show version sudo: true hosts: web_front_end tasks: - name: Create yum cache shell: yum makecache - name: Check the version of Portal shell: rpm -qa | grep portal register: portal - debug: msg={{portal.stdout}} tags: - portal - wfe I would like to get only the TASK: [debug msg={{portal.stdout}}] part. Or even is there a way to get only the shell command output? I have a plugin to format the output. The gist is here but the gist's gist is: # Save as <folder with your playbook>

Ansible to Windows using Kerberos not working

邮差的信 提交于 2019-12-05 19:22:01
I am attempting to use Ansible 1.9.0.1 to configure Windows servers using a domain user name. I have successfully setup the Linux Ansible control box and have been able to use basic auth to run ansible/ansible-playbook plays. However running with a domain user fails. Kerberos is enabled on the Windows nodes: winrm get winrm/config/client/auth Auth Basic = true Digest = true Kerberos = true Negotiate = true Certificate = true CredSSP = true The playbook I am trying to run just references the win_ping module of ansible and the following is the output: PLAY [Manage SMI] **************************

Ansible run task once per database-name

南笙酒味 提交于 2019-12-05 18:58:52
I'm using ansible to deploy several sites to the same server. Each site is a separate 'host' in the ansible hosts inventory, which works really well. However, there are only two databases: production and testing. How can I make sure my database-migration task only runs once per database? I've read into the group_by , run_once and delegate_to features, but I'm not sure how to combine those. The hosts look something like: [production] site1.example.com ansible_ssh_host=webserver.example.com site2.example.com ansible_ssh_host=webserver.example.com [beta] beta-site1.example.com ansible_ssh_host

Playbooks in a subdirectory, not next to group_vars

岁酱吖の 提交于 2019-12-05 17:46:41
问题 Does anyone know how to put playbooks into folders, but share the same roles, group_vars, and other stuff typically located at the root dir? Here's what I'd like to have: root_dir: - group_vars - roles - inventory - playbooks - my_playbook.yml - site.yml - deploy.yml Our root dir is getting pretty big now and I'd like to split out some playbooks into their own folder (shown as playbooks/ above). An identical tiny playbook fails to run when inside a directory (say, playbooks/) vs at the root

Ansible: Get number of hosts in group

。_饼干妹妹 提交于 2019-12-05 13:05:06
问题 I'm trying to get the number of hosts of a certain group. Imagine an inventory file like this: [maingroup] server-[01:05] Now in my playbook I would like to get the number of hosts that are part of maingroup which would be 5 in this case and store that in a variable which is supposed to be used in a template in one of the playbook's tasks. At the moment I'm setting the variable manually which is far from ideal.. vars: HOST_COUNT: 5 回答1: vars: HOST_COUNT: "{{ groups['maingroup'] | length }}"

can roles and tasks exist in the same playbook?

a 夏天 提交于 2019-12-05 11:28:49
问题 --- # file: main.yml - hosts: fotk remote_user: fakesudo tasks: - name: create a developer user user: name={{ user }} password={{ password }} shell=/bin/bash generate_ssh_key=yes state=present roles: - { role: create_developer_environment, sudo_user: "{{ user }}" } - { role: vim, sudo_user: "{{ user }}" } For some reason the create user task is not running. I have searched every key phrase I can think of on Google to find an answer without success. The roles are running which is odd. Is it

Creating multiple times the same role, but with different items

99封情书 提交于 2019-12-05 11:07:06
I have a playbook that prepare 3 different Vagrants in my machine, so I have create a role that create this Vagrant. I don't find the correct syntax. It looks like roles is not a module , so I don't have all options, only tutorials. playbook file : - hosts: localhost connection: local roles : - role: vagrant with_items: - {index: 1, ip: 192.168.222.1, name: mongo1, user: nicorama } - {index: 2, ip: 192.168.222.2, name: mongo2, user: nicorama } - {index: 3, ip: 192.168.222.3, name: mongo3, user: nicorama } And the tasks in the vagrant role - file: path=/linux/{{item.name}} state=directory owner

Ansible: playbook calling Role in a directory that is in the roles directory

断了今生、忘了曾经 提交于 2019-12-05 10:56:28
I would like to shape my directory structure of my ansible roles and playbooks. Currently I have a directory structure like. group_vars * all * group-one - group-vars.yml - group-vault.yml ... host_vars - server1.yml plays - java_plays * deploy_fun_java_stuff.yml * deploy_playbook.yml roles - role1 - tasks * main.yml - handlers - (the rest of the needed directories) - role2 - java - java_role1 - tasks * main.yml - handlers - (the rest of the needed directories) I would like to be able to call upon the role java_role1 in the play deploy_fun_java_stuff.yml I can call --- - name: deploy fun java

How to keep local roles separated from the ones loaded from ansible-galaxy?

故事扮演 提交于 2019-12-05 10:48:35
I observed that roles downloaded from galaxy get installed inside the roles/ directory, where we already have our in-house ones, making quite hard to distiguish between external ones and internal ones. Is there a way to keep them in separated directories, so we can avoid confusions? In most cases I would expect to have a script that is updating the galaxy ones and that we would not modify them internally. I think there is no standard way of doing this but you can use Ansibles behavior to your advantage. Ansible searches in two locations for roles: In the roles directory relative to your