ansible-playbook

Abort execution of remaining task if certain condition is failed

自闭症网瘾萝莉.ら 提交于 2019-12-03 06:22:43
问题 I want to abort execution of remaining task if certain condition is failed. and display proper error message. So instead of skipping remaining task I want to show error message and stop execution of ansible playbook. Lets say I am running below command $ ansible-playbook playbook.yml -e "param1=value1 param2=value" My playbook look like this:- playbook.yml:- --- - hosts: local user: roop gather_facts: no vars: {param1: "", param2: ""} tasks: #check whether param1 defined - name: 'Check for

ansible: include role in a role?

时间秒杀一切 提交于 2019-12-03 05:23:37
问题 Is it possible to reuse a role in a role? I do not mean via defining a dependency in the meta/main.yml file of a role but by including the role in the tasks/main.yml of another role directly? For example, I define a couple of basic roles in rolebooks and some more high level roles in roles. I want the high level roles to include some of the basic roles in addition to some specific tasks. playbooks/ rolebooks/ some_role/ roles/ webtier/ tasks/ main.yml In playbooks/roles/webtier/tasks/main.yml

Ansible SSH ERROR connection in localhost

走远了吗. 提交于 2019-12-03 04:14:19
问题 I have this error when I launch my playbook against the localhost host. TASK [setup] ******************************************************************* fatal: [127.0.0.1]: UNREACHABLE! => {"changed": false, "msg": "SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue", "unreachable": true} to retry, use: --limit @deploy-test-env.retry PLAY RECAP ******************************

How can I write variables inside the tasks file in ansible

旧街凉风 提交于 2019-12-03 04:04:35
问题 I have this play.yml --- - hosts: 127.0.0.1 connection: local sudo: false tasks: - include: apache.yml My Apache look like this: vars: url: czxcxz - name: Download apache shell: wget {{url}} This is giving me error. If I remove vars then it works. But I want to include the vars inside tasks so that I can keep different vars for different tasks separate. 回答1: NOTE: Using set_fact as described below sets a fact/variable onto the remote servers that the task is running against. This fact

How to write dynamic variable in Ansible playbook

戏子无情 提交于 2019-12-03 03:37:48
问题 Based on extra vars parameter I Need to write variable value in ansible playbook ansible-playbook playbook.yml -e "param1=value1 param2=value2 param3=value3" If only param1 passed myvariable: 'param1' If only param1,param2 passed myvariable: 'param1,param2' If param1,param2,param3 are passed then variable value will be myvariable: 'param1,param2,param3' When I try to create variable dynamically through template then my playbook always takes previous variable value. But inside dest=roles

Ansible Handler notify vs register

蓝咒 提交于 2019-12-03 03:27:16
问题 So after reading Ansible docs, I found out that Handlers are only fired when tasks report changes, so for example: some tasks ... notify: nginx_restart # our handler - name: nginx_restart vs some tasks ... register: nginx_restart # do this after nginx_restart changes when: nginx_restart|changed Is there any difference between these 2 methods? When should I use each of them? For me, register seems to have more functionality here, unless I am missing something... 回答1: There are some differences

Ansible: Set variable to file content

亡梦爱人 提交于 2019-12-03 03:23:29
问题 I'm using the ec2 module with ansible-playbook I want to set a variable to the contents of a file. Here's how I'm currently doing it. Var with the filename shell task to cat the file use the result of the cat to pass to the ec2 module. Example contents of my playbook. vars: amazon_linux_ami: "ami-fb8e9292" user_data_file: "base-ami-userdata.sh" tasks: - name: user_data_contents shell: cat {{ user_data_file }} register: user_data_action - name: launch ec2-instance local_action: ... user_data:

How do I pass username and password while using Ansible Git module?

[亡魂溺海] 提交于 2019-12-03 03:10:03
问题 While doing clone, push or pull of a private git repository hosted internally (e.g. on a GitLab instance) with Ansible's Git module, how do I specify username and password to authenticate with the Git server? I don't see any way to do this in the documentation. 回答1: You can use something like this: --- - hosts: all gather_facts: no become: yes tasks: - name: install git package apt: name: git - name: Get updated files from git repository git: repo: "https://{{ githubuser | urlencode }}:{{

Ansible: Store command's stdout in new variable?

纵然是瞬间 提交于 2019-12-03 02:46:21
问题 Inside my playbook I'd like to create a variable holding the output of an external command. Afterwards I want to make use of that variable in a couple of templates. Here are the relevant parts of the playbook: tasks: - name: Create variable from command command: "echo Hello" register: command_output - debug: msg="{{command_output.stdout}}" - name: Copy test service template: src=../templates/test.service.j2 dest=/tmp/test.service - name: Enable test service shell: systemctl enable /tmp/test

include tasks from another role in ansible playbook

醉酒当歌 提交于 2019-12-03 02:33:07
问题 I'm designing a kind of playbook lib with individual tasks so in the usual roles repo, I have something like: roles ├── common │ └── tasks │ ├── A.yml │ ├── B.yml │ ├── C.yml │ ├── D.yml │ ├── login.yml │ ├── logout.yml │ └── save.yml ├── custom_stuff_workflow │ └── tasks │ └── main.yml └── other_stuff_workflow └── tasks └── main.yml my main.yml in custom_stuff_workflow then contain something like: --- - include: login.yml - include: A.yml - include: C.yml - include: save.yml - include: