Hot answers tagged

5

What your are describing can typically be addressed with a correct inventory design. [zone1] serverA serverB serverC [zone2] server1 server2 server3 [zone3] serverX serverY serverZ [jenkins_master] serverA server1 serverX [jenkins_slave] serverB serverC server2 server3 serverY serverZ From there you can easily: create plays that will target a group or ...


5

There are many reasons that using roles is better than using long playbooks, and very few reasons that using a single long playbook is better than using a role. These are almost always clear only at a certain scale. Team size, workload number and complexity and frequency of execution all come into play here and the larger any of them get, the more obvious it ...


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 &...


4

"In the event that variable item.ppsize is not set I want to exclude that entire parameter from being included." Use the default filter to omit module parameters using the special omit variable pp_size: "{{ item.ppsize|default(omit) }}"


4

Thanks for linking your question. Here's the github thread for reference: https://github.com/geerlingguy/ansible-role-certbot/issues/87 There are many different ways to get certs from a CA. certbot (what this repo uses) is just one of the ways which uses letsencrypt as a certificate authority. acme_certificate is more generic and if you can't use ...


4

Use this source code for reboot your client machine --- - name: System Reboot hosts: debian become_method: sudo become_user: root become: true tasks: - name: reboot nodes # Reboot client side debian machine shell: sleep 2 && shutdown -r now "Ansible reboot" async: 1 poll: 0 ...


4

This question runs two risks: of being marked as "primarily opinion-based", and its answers might age poorly. However, I think it's useful to express an opinion, if only for posterity; if and when things change, there may be better answers -- but there will always be blank slates. I would split the problem up into four sections: Infrastructure ...


4

I think you have to consider the history of the two tools to answer this question properly: Ansible was created to manage the installation and maintenance of virtual machines, thus it originally only had the capability to install software into an operating system, perform systems administration tasks within that machine. Subsequently, it has been extended ...


4

This error CannotPullContainerError usually occurs when you have no access to the Internet from ECS and thus it doesn't able to pull an image from registry. Make sure you have networking configured in such a way to have an access to Internet https://stackoverflow.com/questions/48226547/aws-fargate-cannotpullcontainererror-500 Manually you can confirm ...


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 ...


3

You may want to take a look at the ShiningPanda Plugin. It allows running a build step inside a particular python virtual environment, created automatically if it doesn't exist or reused if it already exists. The virtual environment is located outside the workspace, but it can be named and made to appear as a directory with that name inside the workspace. ...


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

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

become_user will tell which user to become to run a particular ansible module on the remote server. If you want to run the ansible command on your control machine as an other user, you need to use sudo or su on this machine e.g. sudo -s -u ansible ansible all -m ping The -s option will load the user's shell an make sure homedir and all other envs are ...


3

https://docs.ansible.com/ansible/latest/modules/reboot_module.html - name: Unconditionally reboot the machine with all defaults reboot: - name: Reboot a slow machine that might have lots of updates to apply reboot: reboot_timeout: 3600


3

I'd suggest that you first put some default values within the playbook (if you explicitly want your variables there, for the purpose of .. reducing interactivity/command line args lets say): - hosts: all vars: user: greatuser passa: greatpassword Second, I'm pretty sure that pass is a reserved word somewhere, although I'm failing to find it in ...


3

Simple one. You should either add ansible_ssh_extra_args="-o StrictHostKeyChecking=no" to inventory or disableHostKeyChecking: true into Jenkins pipeline script (inside ansiblePlaybook block). Like this: ansiblePlaybook( colorized: true, installation: 'ansible27' inventory: '[hostsfile]' playbook: '[playbook]' disableHostKeyChecking: true )


3

Use json_query. For example - set_fact: my_device: "{{ ansible_mounts|json_query(query) }}" vars: query: "[?mount=='/'].device " - debug: var: my_device gives "my_device": [ "/dev/sdc1" ] To get the first element of the list only append the filter first - set_fact: my_device: "{{ ansible_mounts|json_query(query)|first }}"


3

Ansible command module requires only one command and cannot be changed. You should use the shell module at the very least. Note however that this will break the idempotency of the playbook. You should probably split the task up into three: configure task using the shell module. Use creates: to tell the task to be skipped if the configure task has already ...


3

@Argyle explained the --fork 1 trick to achieve a serial run. I suggest you have a look at the reboot module that might be better suited than running a command directly. A quick example that will reboot all your nodes one by one waiting for each to be fully booted before moving to the next one. ansible -i inventory nodes --forks 1 -m reboot Pass needed ...


3

As it says, No such file or directory: 'gpg', so you probably need to install gnupg before adding the PPA repository: apt-get install gnupg


2

Defining default value for ansible variables and overriding them via ansible playbooks can be achieved using Jinja2 templating. - name: Create a new user user: name: "{{ username_variable | default('default_value') }}" password: "{{ password_variable | default('default_value') }}" state: present Then if these variables are passed from the ...


2

Is this what you're looking for? - hosts: all vars: bunch_of_specific_packages: - apache2 - gcc - gedit tasks: - package: name: "{{ item }}" loop: "{{ bunch_of_specific_packages }}"


2

Unless I totally missed your question, roles are exactly what you need in this case. I'll use examples from my real world. My code below is just to illustrate my point (so it is not fully runnable, might contain errors and is not bullet proof rocket science: you will probably have to adapt/overcome tools limitations). But at least you'll be able to tell me ...


2

In 2.5+ (well after the question), there is the debugger which covers most of this: https://docs.ansible.com/ansible/latest/user_guide/playbooks_debugger.html As for one at a time, using "--forks 1" only connects to one system at a time if you want to do it ad-hoc and not every time.


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 ...


2

Several problems in your playbook. loop is basically expecting a list, not a string containing a variable name. You need to expand your variable with a jinja2 expression => loop: "{{ some_list_variable }}" It will be hard to give you the correct syntax without seeing the exact data structure of your result var but... Typically, the register from a loop ...


2

Let's simplify the dictionary in the first task and loop subelements in second. The tasks below - set_fact: nginx_users_selected: "{{ nginx_users_selected| default({})| combine({item.key: item.value}) }}" loop: "{{ nginx_users| dict2items| ...


2

You don't need to be a privileged user (in your local machine) in order to execute Ansible playbook. When using Become : Ansible allows you to ‘become’ another user, different from the user that logged into the machine (remote user). for more details see Understanding Privilege Escalation In your inventory of hosts [/etc/ansible/host] you have specified ...


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