Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Hot answers tagged

4

Append the parameters after the command. See the example below. # ansible -m shell --args "pwd; touch test; ls -1 chdir=/scratch/tmp creates=/scratch/tmp/test" localhost localhost | CHANGED | rc=0 >> /scratch/tmp test # ansible -m shell --args "pwd; touch test; ls -1 chdir=/scratch/tmp creates=/scratch/tmp/test" localhost localhost | SUCCESS | rc=0 &...


3

You hint in the title about immutable infrastructure, so it sounds like you already know the solution: don't change existing servers, but bring up new ones with your changes, switch over to them, and switch back to the old ones if necessary. Theoretically any of the standard config management tools can roll back by simply checking out a previous commit and ...


3

I solved this by adding ignore_errors: true register: results to the no_log-task. This makes ansible continue to the next task, even when the task fails. Then for the next task define a debug task, which always fails and outputs the registered variable, but only runs when the previous task failed: - name: Error output debug: var: results ...


3

Generally, Ansible is very flexible and often there are more "correct" solutions. Start for example with the question "Where do the configuration data come from?", put the default data to the roles and decide which variables should be configured in "group_vars/host_vars", in the roles, and which in the playbooks. Review Variable precedence: Where should I ...


2

Use the --limit option to select a subset of hosts: ansible-playbook -i /path test.yml --tags automation --limit host2 Its description from ansible-playbook documentation: further limit selected hosts to an additional pattern


2

How to formulate the code to get rid of [DEPRECATION WARNING] during runtime? Simply by following the tip in the error message. when: CURRENT_INSTALLED_VERSION.stdout is version(EXPECTED_REMOTE_SOFTWARE_VERSION,'>=') Is there are better way to apply the same logic? I don't see anything wrong if it meets your current needs. Only remark: The first ...


1

The best practice is to separate production and staging(testing) inventory. See Staging vs Production. This way you pick with -i what you are targeting. To make it more robust you might want to clone a separate structure for production and restrict access to it. Pull from staging before deploying to production. In detail, this would mean to 1) put the ...


1

The magic you need is magic variables, in particular the groups variable, which is a dictionary/map with all the groups in inventory and each group has the list of hosts that belong to it. Then you can use template filters to format the list: use map with regex_replace to add the quotes to all list elements and then join them into the final result. {{ ...


1

I met the same situation. I have login1 for my machine, passwordless sudo and login2, under which I should perform some actions. I did not solve it by ansible means. But I made such a workaround: - name: "Install nvm" shell: sudo -u buildkite-agent bash -c "<my commands to be performed on behalf of buildkite-agent>" become: true Such a case: - ...


Only top voted, non community-wiki answers of a minimum length are eligible