# Ansible Automation for an upgrade (5.611 to 6.5.4) of elasticsearch

**URL:** <https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789>\
**Category:** Elasticsearch\
**Created:** [January 18, 2019, 12:33pm UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789 "2019-01-18T12:33:58Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![smm](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@smm](https://discuss.elastic.co/u/smm)\
**Post date:** [January 18, 2019, 12:33pm UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789/1 "2019-01-18T12:33:58Z")

</div>

Hi there,  
quick question to the community. If you make an elasticsearch upgrade manually you are prompted if you want to keep the defaults. Does somenone has a solution for this step when using Ansible? So, how can I emulate 'yes, keep the existing configs (N ist the standard answer)' using ansible?

Do you know a way of solving this perhaps pimping this statement?  
- name: doing elasticsearch upgrade  
apt:  
name: elasticsearch=6.5.4  
only\_upgrade: yes  
environment:  
RUNLEVEL: 1

Thank you very much!

---

<div class="post-metadata">

**Author:** ![michael.russell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael.russell/32/27889_2.png) [@michael.russell](https://discuss.elastic.co/u/michael.russell)\
**Post date:** [January 21, 2019, 12:32pm UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789/2 "2019-01-21T12:32:49Z")

</div>

Hi Stefano!

This upgrade seems to work with our official playbook so it is possible. You can take a look at the [install task](https://github.com/elastic/ansible-elasticsearch/blob/2aa0b38449336cd5072457c01efb2d31c08823d3/tasks/elasticsearch-Debian.yml#L57-L69) to see what you might be missing.

My first guess would be that you need to set the `ES_PATH_CONF` to avoid the questions that apt asks.

```auto
  environment:
    ES_PATH_CONF: "/etc/elasticsearch"

```

---

<div class="post-metadata">

**Author:** ![smm](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@smm](https://discuss.elastic.co/u/smm)\
**Post date:** [January 28, 2019, 11:55am UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789/3 "2019-01-28T11:55:52Z")

</div>

Thanks for the input.

I think mine is a more basic question. Meaning: If I upgrade manually via deb package I get 2 questions. For example one is:  
Configuration file '/etc/elasticsearch/elasticsearch.yml'  
==\> Modified (by you or by a script) since installation.  
==\> Package distributor has shipped an updated version.  
What would you like to do about it ? Your options are:  
Y or I : install the package maintainer's version  
N or O : keep your currently-installed version  
D : show the differences between the versions  
Z : start a shell to examine the situation  
The default action is to keep your current version.  
\*\*\* elasticsearch.yml (Y/I/N/O/D/Z) [default=N] ?

Now, how can I handle in ansible to give an answer using a playbook. Am I completely on a false track or how do you solve this?  
Thank you very much for any input.  
Cheers.

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [January 28, 2019, 12:26pm UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789/4 "2019-01-28T12:26:24Z")

</div>

Usually apt install -y should solve that problem, it assumes yes on all questions.

---

<div class="post-metadata">

**Author:** ![smm](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@smm](https://discuss.elastic.co/u/smm)\
**Post date:** [January 28, 2019, 1:03pm UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789/5 "2019-01-28T13:03:01Z")

</div>

....yep, correct ;-). BUt: is there a way to do this with ansible?

---

<div class="post-metadata">

**Author:** ![pjanzen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pjanzen/32/13756_2.png) [@pjanzen](https://discuss.elastic.co/u/pjanzen)\
**Post date:** [January 28, 2019, 1:07pm UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789/6 "2019-01-28T13:07:17Z")

</div>

I'm not a ansible user myself, we use saltstack to do our config managment. but [this thread](https://stackoverflow.com/questions/41871918/how-to-let-ansible-answer-yes-to-everything-sendmailconfig-asks) on stackoverflow might push you in the right direction..

---

<div class="post-metadata">

**Author:** ![michael.russell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael.russell/32/27889_2.png) [@michael.russell](https://discuss.elastic.co/u/michael.russell)\
**Post date:** [January 29, 2019, 4:02pm UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789/7 "2019-01-29T16:02:23Z")

</div>

> Now, how can I handle in ansible to give an answer using a playbook. Am I completely on a false track or how do you solve this?

Which version of Ansible are you using? It's weird that this works just fine for the official Ansible Elasticsearch playbook without needing any special configuration. The tests are being run with version `2.4.3.0` and includes testing of upgrades from 5.x to 6.x.

Version is really the only difference I can see here. Can you also post the output that you get from Ansible when it tries to upgrade?

---

<div class="post-metadata">

**Author:** ![smm](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@smm](https://discuss.elastic.co/u/smm)\
**Post date:** [February 1, 2019, 12:00pm UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789/8 "2019-02-01T12:00:43Z")

</div>

Hello Michael,  
I am working under ansible 2.6.3.  
Would you mind to post the link for the official elastic upgrade playbook?  
Thank you.

What I am doing right now is as simple as this at this point:  
- name: doing elasticsearch upgrade  
apt:  
name: elasticsearch=6.5.4  
install\_recommends: yes  
allow\_unauthenticated: yes  
environment:  
RUNLEVEL: 1

But so, I have no choice to say if I wanto to accept the defaults. I am still learning ansible that is why I was interested to know if there is some way to script in the plays to accept or nor the given choices.

Thank you and kind regards  
Stefano

---

<div class="post-metadata">

**Author:** ![michael.russell](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael.russell/32/27889_2.png) [@michael.russell](https://discuss.elastic.co/u/michael.russell)\
**Post date:** [February 4, 2019, 3:20pm UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789/9 "2019-02-04T15:20:13Z")

</div>

> I am still learning ansible that is why I was interested to know if there is some way to script in the plays to accept or nor the given choices.

Ansible is just going to run `apt-get -y` (with some other options too). It's not something that you need to specify yourself.

> Would you mind to post the link for the official elastic upgrade playbook?

This is the task for the [ansible-elasticsearch](https://github.com/elastic/ansible-elasticsearch/blob/2aa0b38449336cd5072457c01efb2d31c08823d3/tasks/elasticsearch-Debian.yml#L57-L69) playbook. It's almost identical to yours which is why it is weird that you are running in to problems. As part of our automated testing we even check that upgrading from 5.x to 6.x is possible. If using the same settings doesn't work you could try it with ansible `2.4.3.0` to be sure that isn't something that has broken with ansible.

---

<div class="post-metadata">

**Author:** ![smm](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@smm](https://discuss.elastic.co/u/smm)\
**Post date:** [February 5, 2019, 5:51am UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789/10 "2019-02-05T05:51:26Z")

</div>

...so: using ansible I have no possibility to make a choice at this 2 points that came up during a manual install:

Configuration file '/etc/elasticsearch/elasticsearch.yml'  
==\> Modified (by you or by a script) since installation.  
==\> Package distributor has shipped an updated version.  
What would you like to do about it ? Your options are:  
Y or I : install the package maintainer's version  
N or O : keep your currently-installed version  
D : show the differences between the versions  
Z : start a shell to examine the situation  
The default action is to keep your current version.  
\*\*\* elasticsearch.yml (Y/I/N/O/D/Z) [default=N] ?

Configuration file '/etc/default/elasticsearch'  
==\> Modified (by you or by a script) since installation.  
==\> Package distributor has shipped an updated version.  
What would you like to do about it ? Your options are:  
Y or I : install the package maintainer's version  
N or O : keep your currently-installed version  
D : show the differences between the versions  
Z : start a shell to examine the situation  
The default action is to keep your current version.  
\*\*\* elasticsearch (Y/I/N/O/D/Z) [default=N] ?

MEANING: There is no way to tell ansible: hey, answer with e.g. Y in both cases to get the maintaner's version?

Thank you again for your input! I just want to learn it right. I think this is an important question. I could also decide: ok, the first answer is N and the second I would like a Y.

cheers  
Stefano

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 5, 2019, 5:51am UTC](https://discuss.elastic.co/t/ansible-automation-for-an-upgrade-5-611-to-6-5-4-of-elasticsearch/164789/11 "2019-03-05T05:51:30Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
