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

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

"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

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


4

The issue seems resolved, If I escape the backslash in the regex too: - name: Remove LE webroot definition lineinfile: path: "/etc/path/to/config/{{ inventory_hostname }}.conf" regexp: "^{{ inventory_hostname | replace('.', '\\.') }} = /path/to/a/directory" state: absent


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

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


3

Robuster and more practical solution is an encrypted file. For example shell> cat vault1.yml my_email: admin@example.com my_tag: tag123 shell> ansible-vault encrypt vault1.yml Encryption successful shell> cat vault1.yml $ANSIBLE_VAULT;1.1;AES256 33376431383930313965356364356136306338383238303032363165633962636366663939373237 ...


3

Try this, to run an adhoc command with IP address ansible all -i 192.168.254.150, -m ping 192.168.254.150 | SUCCESS => { "changed": false, "ping": "pong" } From man: -i INVENTORY, --inventory=INVENTORY, --inventory-file=INVENTORY specify inventory host path or comma separated host


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


2

Q: Is it possible to have a pair of IPs in Ansible? A: Yes. It is possible. For example, it might be useful to create groups in the inventory with all pieces of information. [primary] 1.1.1.1 1.1.1.3 1.1.1.5 [standby] 1.1.1.2 1.1.1.4 1.1.1.6 [ha] 1.1.1.1 stdby=1.1.1.2 1.1.1.3 stdby=1.1.1.4 1.1.1.5 stdby=1.1.1.6 It's possible to simplify the fetching of ...


2

If I understood you correctly, you need free strategy. It will run all tasks ASAP, not waiting for anything. https://docs.ansible.com/ansible/latest/plugins/strategy/free.html Bear in mind, that logs will be a mess :)


2

You can certainly do this through a handler or task, but first you need to generate the trigger conditions. The swap space is in the Ansible facts that are returned when setup: is run. From the Ansible docs: Facts These are variables that contain information pertinent to the current host (inventory_hostname). They are only available if gathered first....


2

I suspect what is happening here is you are trying to insert the private key into the authorized_keys file, which is invalid as only the public key is required on the target machine. What you need to do is extract the public key from the private key: - name: Generate an OpenSSL public key with a passphrase protected private key openssl_publickey: ...


2

Maybe a simple shell script would be more useful. If must to use ansible, it could be something like that (assuming you have all servers in group testall): - hosts: testall connection: local gather_facts: false tasks: - wait_for: timeout: 2 port: 43 host: '{{ (ansible_ssh_host|default(ansible_host))|default(...


2

There are a couple of possibilities based upon my experience: You may not have specified region-id in Ansible, which means it will default to the region of the Resource Group. Thus you may have a Resource Group in a region that does in-fact not support Standard_D4s_v3. From time to time specific instance types are unavailable in a region due to resource ...


2

I suspect you haven't set up the host in your inventory you can figure out where your hosts are being pulled from with the following command: ansible-config dump | grep HOST In practice, you probably just need to create an inventory file with the following content: [nodes] node01 ansible_host=IP OF YOUR FIRST NODE HERE!!! node02 ansible_host=35.228.80.9 ...


2

You have this in your config file: [inventory] enable_plugins = host_list, script, auto, yaml, ini, toml Do you really need all these plugins? If not, they'll just add time to your processing. There is also a small chance that one of them is successfully parsing your inventory file as an empty inventory. And the documentation states that Once an ...


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