ansible-2.x

How to use omit with Ansible and avoid any errors?

吃可爱长大的小学妹 提交于 2019-11-30 22:15:45
I tried to use omit with an expression like this: id: "{{ openstack_networks.id | default(omit) }}" But it seems that it keeps failing with an exception when openstack_networks variable is not defined. What is the correct way to write this jinja2 filter? I want to omit the parameter in case openstack_networks.id does not exists. Not super elegant, but 100% working solution to handle keys of possibly undefined parent dicts: id: "{{ (openstack_networks | default({})).id | default(omit) }}" This will give you omit if openstack_networks is defined but has no id key or if openstack_networks is

Is it possible to have Ansible retry on connection failure?

不羁岁月 提交于 2019-11-30 17:52:56
I am facing this annoying bug: Ansible hosts are randomly unreachable #18188 . Is there a way to tell Ansible that if SSH connection fails, to try it once more? Or 2 times more? According this post New SSH Retry In Ansible 2.0? there is "retries" option but it doesn't seem very trustworthy to me, the person who posted didn't even get SSH header right and there is no mention of this in Ansible docs. Yes, it is possible using the method which you referenced in your question, i.e. by placing the following parameter in ansible.cfg : [ssh_connection] retries=2 Here is the line that reads retries

Ansible lineinfile - modify a line

对着背影说爱祢 提交于 2019-11-30 17:11:42
问题 I'm new to Ansible and trying to modify a line in /etc/default/grub to enable auditing. I need to add audit=1 within the quotes somewhere on a line that looks like: GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap biosdevname=0 net.ifnames=0 rhgb quiet net.ifnames=0" So far I've managed to delete the line and am only left with net.ifnames=0, audit=1 when I use something like lineinfile: state: present dest: /etc/default/grub backrefs: yes regexp: "net.ifnames=0

Running a playbook on multiple host groups one at a time

元气小坏坏 提交于 2019-11-30 15:15:47
I want to run a playbook containing some roles on multiple host groups I create dynamically with the group_by module. I'm able to do it like the example below (ping replacing my actual role). I was wondering if there is a way to run each group separately in a loop instead of listing all instance ids. I don't want to create a duplicate line with every instance id. The purpose here is to deploy to one instance in every data center at a time instead of running all with a low serial which takes a long time. There might be a different way of doing it, I don't want to create static groups in the

Ansible: copy a directory content to another directory

烈酒焚心 提交于 2019-11-30 11:47:03
问题 I am trying to copy the content of dist directory to nginx directory. - name: copy html file copy: src=/home/vagrant/dist/ dest=/usr/share/nginx/html/ But when I execute the playbook it throws an error: TASK [NGINX : copy html file] ************************************************** fatal: [172.16.8.200]: FAILED! => {"changed": false, "failed": true, "msg": "attempted to take checksum of directory:/home/vagrant/dist/"} How can I copy a directory that has another directory and a file inside?

Unexpected Exception: name 'basestring' is not defined when invoking ansible2

扶醉桌前 提交于 2019-11-30 04:11:41
I'm trying to execute ansible2 commnads... When I do: ansible-playbook -vvv -i my/inventory my/playbook.yml I get: Unexpected Exception: name 'basestring' is not defined the full traceback was: Traceback (most recent call last): File "/usr/local/bin/ansible-playbook", line 85, in <module> sys.exit(cli.run()) File "/usr/local/lib/python3.4/site-packages/ansible/cli/playbook.py", line 150, in run results = pbex.run() File "/usr/local/lib/python3.4/site-packages/ansible/executor/playbook_executor.py", line 87, in run self._tqm.load_callbacks() File "/usr/local/lib/python3.4/site-packages/ansible

Ansible: copy a directory content to another directory

跟風遠走 提交于 2019-11-30 01:18:58
I am trying to copy the content of dist directory to nginx directory. - name: copy html file copy: src=/home/vagrant/dist/ dest=/usr/share/nginx/html/ But when I execute the playbook it throws an error: TASK [NGINX : copy html file] ************************************************** fatal: [172.16.8.200]: FAILED! => {"changed": false, "failed": true, "msg": "attempted to take checksum of directory:/home/vagrant/dist/"} How can I copy a directory that has another directory and a file inside? You could use the synchronize module. The example from the documentation: # Synchronize two directories

Running a playbook on multiple host groups one at a time

China☆狼群 提交于 2019-11-29 21:56:16
问题 I want to run a playbook containing some roles on multiple host groups I create dynamically with the group_by module. I'm able to do it like the example below (ping replacing my actual role). I was wondering if there is a way to run each group separately in a loop instead of listing all instance ids. I don't want to create a duplicate line with every instance id. The purpose here is to deploy to one instance in every data center at a time instead of running all with a low serial which takes a

Unexpected Exception: name 'basestring' is not defined when invoking ansible2

血红的双手。 提交于 2019-11-28 23:33:39
问题 I'm trying to execute ansible2 commnads... When I do: ansible-playbook -vvv -i my/inventory my/playbook.yml I get: Unexpected Exception: name 'basestring' is not defined the full traceback was: Traceback (most recent call last): File "/usr/local/bin/ansible-playbook", line 85, in <module> sys.exit(cli.run()) File "/usr/local/lib/python3.4/site-packages/ansible/cli/playbook.py", line 150, in run results = pbex.run() File "/usr/local/lib/python3.4/site-packages/ansible/executor/playbook

Ansible remote_user vs ansible_user

旧巷老猫 提交于 2019-11-28 22:53:00
The question is simple: what is the difference between ansible_user (former ansible_ssh_user ) and remote_user in Ansible, besides that the first one is set if configuration file and the latter one is set in plays / roles? How do they relate to -u / --user command line options? slayedbylucifer They both seem to be the same. Take a look here: https://github.com/ansible/ansible/blob/c600ab81ee/lib/ansible/playbook/play_context.py#L46-L55 # the magic variable mapping dictionary below is used to translate # host/inventory variables to fields in the PlayContext # object. The dictionary values are