ansible-2.x

Ansible: Detect if a Linux filesystem is mounted read-only

偶尔善良 提交于 2020-01-06 12:41:16
问题 I'm trying to detect if a particular filesystem is mounted read-only or read-write on Linux (Ubuntu 16.04). Using the stat module won't work because it always returns the posix permissions regardless of the actual ability to write into the directory. I'm able to accomplish this with the rather intrusive and cumbersome code below, which attempts to create a dot file. I'd appreciate a cleaner and more elegant alternative, that can also detect if the directory is not a mount point (which would

How to use return values of one task in another task for a different host in ansible

岁酱吖の 提交于 2020-01-06 08:16:26
问题 I was trying to setup mysql master slave replication with ansible for a hostgroup consisting of 2 mysql hosts. Here is my scenario: I run one task in the 1st host and skips the 2nd host, so the 1st task (i.e master replication status) returns some values like Position, File etc. Then, I run another task in 2nd host (skips the 1st hosts), This task uses the return values of the 1st task like master.Position, master.File etc. Now, when I run the playbook, the variables of the 1st task does not

How to use return values of one task in another task for a different host in ansible

浪尽此生 提交于 2020-01-06 08:14:25
问题 I was trying to setup mysql master slave replication with ansible for a hostgroup consisting of 2 mysql hosts. Here is my scenario: I run one task in the 1st host and skips the 2nd host, so the 1st task (i.e master replication status) returns some values like Position, File etc. Then, I run another task in 2nd host (skips the 1st hosts), This task uses the return values of the 1st task like master.Position, master.File etc. Now, when I run the playbook, the variables of the 1st task does not

Ansible: Attach role to user in postgres

妖精的绣舞 提交于 2020-01-06 08:06:27
问题 I am already having a role in Postgres namely readonly . It has readonly access on all the tables in all the databases. I want to attach this role to a user so that he/she also gets the readonly access on all tables in one command. How can I perform the following command using ansible's postgresql_user module? mydb=> grant readonly to dev_username; EDIT: adding more details This is what I have tried, - name: Postgres postgresql_user: login_host: xx.xx.com login_password: mypassword login_user

Error in Mount Module in Ansible

别来无恙 提交于 2020-01-06 04:45:10
问题 I am trying to mount a remote directory. Following is the code: - name: mount the folder. mount: name=/mnt/point src="//sdfs601/master.src/scm/pkgs" fstype=auto opts="domain=td,username=uname,password=pass,file_mode=0777,dir_mode=0777" state=mounted But it is giving the following error: fatal: [153.64.221.181]: FAILED! => {"changed": false, "failed": true, "msg": "Error mounting /mnt/15.00: mount: special device //sdfs601/master.src/scm/pkgs does not exist\n"} But when i try mounting using

Ansible read multiple variables with same name from vars_file

岁酱吖の 提交于 2020-01-05 13:01:11
问题 In my ~/ip_vars_file , I have ip : 10.20.30 ip : 10.20.31 ip : 10.20.32 This is created with lineinfile, lineinfile: line="ip{{':'}} {{item.public_ip}}" dest="{{ansible_env.HOME}}/ip_vars_file}}" with_items: servers.tagged_instances #servers is registered in previous task I am unable to read all three ips as with_items. I get only the last IP in my playbook. --- - hosts: localhost tasks: - name: print ips debug: var: item with_items: "{{ ip }}" vars_files: - ~/ip_vars_file The output I am

Ansible read multiple variables with same name from vars_file

不想你离开。 提交于 2020-01-05 13:00:30
问题 In my ~/ip_vars_file , I have ip : 10.20.30 ip : 10.20.31 ip : 10.20.32 This is created with lineinfile, lineinfile: line="ip{{':'}} {{item.public_ip}}" dest="{{ansible_env.HOME}}/ip_vars_file}}" with_items: servers.tagged_instances #servers is registered in previous task I am unable to read all three ips as with_items. I get only the last IP in my playbook. --- - hosts: localhost tasks: - name: print ips debug: var: item with_items: "{{ ip }}" vars_files: - ~/ip_vars_file The output I am

How to compare kernel (or other) version numbers in Ansible

最后都变了- 提交于 2020-01-02 00:56:06
问题 For a role I'm developing I need to verify that the kernel version is greater than a particular version. I've found the ansible_kernel value, but is there an easy way to compare this to other versions? I thought I might manually explode the version string on the '.'s & compare the numbers, but I can't even find a friendly filter to explode the version string out, so I'm at a loss. Thanks in advance. T 回答1: There is a test for it: {{ ansible_distribution_version | version_compare('12.04', '>='

Correct way to create dynamic lists in Ansible

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-01 04:52:06
问题 I'm looking for advice. I have the following code that creates a list dynamically that I can then later use in a template. This is a copy of the test code I put together - for the actual role I just added the admins|regex_replace variable into the j2 template. --- - hosts: localhost gather_facts: false vars: # define empty admins var first so ansible doesn't complain admins: admin_accounts: - name: john uid: 1000 group: sysadmin shell: /bin/bash comment: "Unix Administrator" - name: paul uid:

Ansible regex escape dollar character

丶灬走出姿态 提交于 2019-12-31 04:13:26
问题 I'm trying to modify URL value in config file using Ansible $CONSOLE_URI = "http://172.18.18.103/controller/"; I'm using lineinfile module, but it doesn't work, I have tried to escape $ with double back slashes, but it hasn't worked either. - lineinfile: dest=/etc/log.conf regexp='^\\$CONSOLE_URI' line='$CONSOLE_URI=http://google.com'; 回答1: I think your regex is correct. I just tested this and the line written to the file actually has the quotes inside. This is the content of /etc/log.conf :